Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > preprocessor question

Reply
Thread Tools

preprocessor question

 
 
Gand Alf
Guest
Posts: n/a
 
      02-14-2011
With the following macros:
# define errno retrieve_errno_func()
# define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
what should happen when you do:
# include SUBSYSTEM_INCLUDE(posix, errno.h)

gcc2.95 pre-processes as intended, to:
# include <posix/include/errno.h>
however gcc3.4 preprocessed to:
# include <posix/include/retrueve_errno_func()>

My guess is that gcc3.4 was the correct one, even though it didn't
produce the intended result.
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-14-2011
Gand Alf <(E-Mail Removed)> writes:

> With the following macros:
> # define errno retrieve_errno_func()
> # define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
> what should happen when you do:
> # include SUBSYSTEM_INCLUDE(posix, errno.h)
>
> gcc2.95 pre-processes as intended, to:
> # include <posix/include/errno.h>
> however gcc3.4 preprocessed to:
> # include <posix/include/retrueve_errno_func()>
>
> My guess is that gcc3.4 was the correct one, even though it didn't
> produce the intended result.


Well neither, but that's just a typo. You should expect:

# include <posix/include/retrieve_errno_func().h>

(modulo spacing). The result of a macro expansion is scanned for other
macros. (The "other" is critical -- the macro being expanded is not
recognised when scanning the expansion.)

--
Ben.
 
Reply With Quote
 
 
 
 
Gand Alf
Guest
Posts: n/a
 
      02-15-2011
Ben Bacarisse writes:

> Gand Alf <(E-Mail Removed)> writes:
>
>> With the following macros:
>> # define errno retrieve_errno_func()
>> # define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
>> what should happen when you do:
>> # include SUBSYSTEM_INCLUDE(posix, errno.h)
>>
>> gcc2.95 pre-processes as intended, to: # include
>> <posix/include/errno.h>
>> however gcc3.4 preprocessed to:
>> # include <posix/include/retrueve_errno_func()>
>>
>> My guess is that gcc3.4 was the correct one, even though it didn't
>> produce the intended result.

>
> Well neither, but that's just a typo. You should expect:
>
> # include <posix/include/retrieve_errno_func().h>
>
> (modulo spacing). The result of a macro expansion is scanned for other
> macros. (The "other" is critical -- the macro being expanded is not
> recognised when scanning the expansion.)


However as I understand it, the header-name is a indivisible token, so it
should not be split and substituted.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-15-2011
Gand Alf <(E-Mail Removed)> writes:

> Ben Bacarisse writes:
>
>> Gand Alf <(E-Mail Removed)> writes:
>>
>>> With the following macros:
>>> # define errno retrieve_errno_func()
>>> # define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
>>> what should happen when you do:
>>> # include SUBSYSTEM_INCLUDE(posix, errno.h)
>>>
>>> gcc2.95 pre-processes as intended, to: # include
>>> <posix/include/errno.h>
>>> however gcc3.4 preprocessed to:
>>> # include <posix/include/retrueve_errno_func()>
>>>
>>> My guess is that gcc3.4 was the correct one, even though it didn't
>>> produce the intended result.

>>
>> Well neither, but that's just a typo. You should expect:
>>
>> # include <posix/include/retrieve_errno_func().h>
>>
>> (modulo spacing). The result of a macro expansion is scanned for other
>> macros. (The "other" is critical -- the macro being expanded is not
>> recognised when scanning the expansion.)

>
> However as I understand it, the header-name is a indivisible token, so it
> should not be split and substituted.


A header-name preprocessing token is only recognised when it occurs in
an include directive[1]. By the way, if it always made an indivisible
token you would expect

# include <subsystem/include/file>

as the result so it's clear that something special is happening in this
case.

In effect, there is no header-name token until after the macros are
expanded. This is an exceptional situation: the header-name token is
formed from the tokens that result from the expansion. Making new
tokens from old does not normally happen (except when using ##) so
#include is a special case.

[1] ... and in some implementation defined location in pragmas according
to 6.4 p4.

--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
preprocessor, token concatenation, no valid preprocessor token Cronus C++ 1 07-14-2004 11:10 PM
a question about preprocessor xuatla C++ 1 07-10-2004 11:03 AM
preprocessor implementation GURU question Dan W. C++ 9 12-04-2003 02:24 AM
Preprocessor's question C Programming 1 09-12-2003 05:32 PM



Advertisments