Gand Alf <> writes:
> Ben Bacarisse writes:
>
>> Gand Alf <> 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.
|