preprocessor question

G

Gand Alf

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.
 
B

Ben Bacarisse

Gand Alf said:
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.)
 
G

Gand Alf

Ben said:
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.
 
B

Ben Bacarisse

Gand Alf said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,952
Messages
2,570,111
Members
46,695
Latest member
Juliane58C

Latest Threads

Top