public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: problem with macro expansion in GCC
@ 2001-02-06 10:15 David Korn
  0 siblings, 0 replies; 6+ messages in thread
From: David Korn @ 2001-02-06 10:15 UTC (permalink / raw)
  To: 'Puneet Singhal', Dhanabal Ekambaram, gcc-help

   What happens if you try

#define XXX(N) N ## .ptr  

 or perhaps

#define CAT(a, b) a ## b
#define XXX(N)    CAT(N, .ptr)
 
  One or other of those should work.  You can't ask macros to concatenate
two strings just by writing them next to each other, you have to use
the pre-processor pasting command ##.

       DaveK
-- 
we are not seats or eyeballs or end users or consumers.
we are human beings - and our reach exceeds your grasp.
                    deal with it.                      - cluetrain.org 

>-----Original Message-----
>From: Puneet Singhal [ mailto:puneet@opussoft.com ]
>Sent: 06 February 2001 04:54
>To: Dhanabal Ekambaram; gcc-help@gcc.gnu.org
>Subject: RE: problem with macro expansion in GCC
>Importance: High
>
>
>I tried it on my machine (solaris sparc 7 and gcc 2.95.2)
>I get " y .ptr" instead of desirable "y.ptr".
>
>Even I cant figure out why?
>
>Puneet
>
>>-----Original Message-----
>>From: gcc-help-owner@gcc.gnu.org [ mailto:gcc-help-owner@gcc.gnu.org]On
>>Behalf Of Dhanabal Ekambaram
>>Sent: Tuesday, February 06, 2001 8:36 AM
>>To: 'gcc-help@gcc.gnu.org'
>>Subject: problem with macro expansion in GCC
>>
>>
>>Hi,
>>
>>When I use
>>
>>#define XXX(N)  N.ptr
>>
>>XXX(y) gets transformed to " y.ptr" instead of "y.ptr".
>>I am not sure why i am getting this leading space in the 
>expanded string.
>>
>>Can anybody help me to eliminate this problem?
>>
>>Thanks,
>>dhanabal
>
>


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: problem with macro expansion in GCC
@ 2001-02-07  1:36 David Korn
  0 siblings, 0 replies; 6+ messages in thread
From: David Korn @ 2001-02-07  1:36 UTC (permalink / raw)
  To: 'Dhanabal Ekambaram', 'Puneet Singhal', gcc-help

>Hi David & Puneet,
>
>Thanks for the comments.
>
>I did try with concatenation already. It takes care of
>the space between "N" and the ".".  But, I do get
>a leading space wherever I use this macro.
>
>If I have 
>x = a.XXX(b);
>
>I expect it to change to
>x = a.b.ptr;
>
>but, it changes to
>x = a. b.ptr;
>

   Hi Dhanabal,

 You have to use concatenation *again* to join "a" and "XXX(b)"; it is 
part of how the preprocessor is defined to work that it won't just 
concatenate tokens like that.  Macro definitions are special items and
the spaces are introduced deliberately to prevent them from unexpectedly
joining onto other things.

 x = CAT(a, XXX(b));

        DaveK
-- 
we are not seats or eyeballs or end users or consumers.
we are human beings - and our reach exceeds your grasp.
                    deal with it.                      - cluetrain.org 

>-----Original Message-----
>From: Dhanabal Ekambaram [ mailto:Dhanabal@Zambeel.com ]
>Sent: 06 February 2001 18:32
>To: David Korn; 'Puneet Singhal'; gcc-help@gcc.gnu.org
>Subject: RE: problem with macro expansion in GCC
>
>
>dhanabal
>
>>   What happens if you try
>>#define XXX(N) N ## .ptr  
>>
>> or perhaps
>>
>>#define CAT(a, b) a ## b
>>#define XXX(N)    CAT(N, .ptr)
>> 
>>  One or other of those should work.  You can't ask macros to 
>concatenate
>>two strings just by writing them next to each other, you have to use
>>the pre-processor pasting command ##.
>


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: problem with macro expansion in GCC
  2001-02-05 19:06 Dhanabal Ekambaram
  2001-02-05 20:50 ` Puneet Singhal
@ 2001-02-06 12:35 ` Alexandre Oliva
  1 sibling, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2001-02-06 12:35 UTC (permalink / raw)
  To: Dhanabal Ekambaram; +Cc: 'gcc-help@gcc.gnu.org'

On Feb  6, 2001, Dhanabal Ekambaram <Dhanabal@Zambeel.com> wrote:

> #define XXX(N)  N.ptr

> XXX(y) gets transformed to " y.ptr" instead of "y.ptr".

That's to prevent unwanted token pasting, if XXX(y) happens to be
preceded by something that might be seem like the same token.  This
would unlikely be the case for this particular macro, but how is the
preprocessor to know that?

In any case, the extra space shouldn't be a problem for you; the
compiler will simply discard it.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: problem with macro expansion in GCC
@ 2001-02-06 10:33 Dhanabal Ekambaram
  0 siblings, 0 replies; 6+ messages in thread
From: Dhanabal Ekambaram @ 2001-02-06 10:33 UTC (permalink / raw)
  To: 'David Korn', 'Puneet Singhal', gcc-help

Hi David & Puneet,

Thanks for the comments.

I did try with concatenation already. It takes care of
the space between "N" and the ".".  But, I do get
a leading space wherever I use this macro.

If I have 
x = a.XXX(b);

I expect it to change to
x = a.b.ptr;

but, it changes to
x = a. b.ptr;

Thanks,
dhanabal

>   What happens if you try
>#define XXX(N) N ## .ptr  
>
> or perhaps
>
>#define CAT(a, b) a ## b
>#define XXX(N)    CAT(N, .ptr)
> 
>  One or other of those should work.  You can't ask macros to concatenate
>two strings just by writing them next to each other, you have to use
>the pre-processor pasting command ##.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: problem with macro expansion in GCC
  2001-02-05 19:06 Dhanabal Ekambaram
@ 2001-02-05 20:50 ` Puneet Singhal
  2001-02-06 12:35 ` Alexandre Oliva
  1 sibling, 0 replies; 6+ messages in thread
From: Puneet Singhal @ 2001-02-05 20:50 UTC (permalink / raw)
  To: Dhanabal Ekambaram, gcc-help

I tried it on my machine (solaris sparc 7 and gcc 2.95.2)
I get " y .ptr" instead of desirable "y.ptr".

Even I cant figure out why?

Puneet

>-----Original Message-----
>From: gcc-help-owner@gcc.gnu.org [ mailto:gcc-help-owner@gcc.gnu.org]On
>Behalf Of Dhanabal Ekambaram
>Sent: Tuesday, February 06, 2001 8:36 AM
>To: 'gcc-help@gcc.gnu.org'
>Subject: problem with macro expansion in GCC
>
>
>Hi,
>
>When I use
>
>#define XXX(N)  N.ptr
>
>XXX(y) gets transformed to " y.ptr" instead of "y.ptr".
>I am not sure why i am getting this leading space in the expanded string.
>
>Can anybody help me to eliminate this problem?
>
>Thanks,
>dhanabal


^ permalink raw reply	[flat|nested] 6+ messages in thread

* problem with macro expansion in GCC
@ 2001-02-05 19:06 Dhanabal Ekambaram
  2001-02-05 20:50 ` Puneet Singhal
  2001-02-06 12:35 ` Alexandre Oliva
  0 siblings, 2 replies; 6+ messages in thread
From: Dhanabal Ekambaram @ 2001-02-05 19:06 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

Hi,

When I use

#define XXX(N)  N.ptr

XXX(y) gets transformed to " y.ptr" instead of "y.ptr".
I am not sure why i am getting this leading space in the expanded string.

Can anybody help me to eliminate this problem?

Thanks,
dhanabal

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-02-07  1:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-06 10:15 problem with macro expansion in GCC David Korn
  -- strict thread matches above, loose matches on Subject: below --
2001-02-07  1:36 David Korn
2001-02-06 10:33 Dhanabal Ekambaram
2001-02-05 19:06 Dhanabal Ekambaram
2001-02-05 20:50 ` Puneet Singhal
2001-02-06 12:35 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).