[cpp] using expressions inside a #define label

A

Andrey Vul

Is there a way to make this parseable by cpp:

#define foo abc
#define bar def

#define foo##bar baz

, so that a file, #include-ing the file containing the above
expression will have
a #define abcdef baz
in it?

I remember something along the lines of this in IOCCC, but not the
actual implementation.
 
A

Andrey Vul

Is there a way to make this parseable by cpp:

#define foo abc
#define bar def

#define foo##bar baz

, so that a file, #include-ing the file containing the above
expression will have
a #define abcdef baz
in it?

I remember something along the lines of this in IOCCC, but not the
actual implementation.

I think it was in this format:
cpp foo.c > 1.c
cpp 1.c > 2.c
cpp 2.c > 3.c
cc 3.c -o foo

Does this mean that it's strictly not possible to do a multi-stage
preprocessing without creation of temporary files?
inline will not work because I'm using #define() to return a reference
(i.e. dereferenced pointer), similar to how errno is implemented in
MSVC:
#define errno (*_errno())

But the label is not guaranteed to be static for every inclusion of
the file. Does this mean that external preprocessing, as is in the
IOCCC example, is needed?
 
G

Gene

I think it was in this format:
cpp foo.c > 1.c
cpp 1.c > 2.c
cpp 2.c > 3.c
cc 3.c -o foo

Does this mean that it's strictly not possible to do a multi-stage
preprocessing without creation of temporary files?
inline will not work because I'm using #define() to return a reference
(i.e. dereferenced pointer), similar to how errno is implemented in
MSVC:
#define errno (*_errno())

But the label is not guaranteed to be static for every inclusion of
the file. Does this mean that external preprocessing, as is in the
IOCCC example, is needed?

If you need to do these kinds of tricks, you are probably better off
using m4 or some other more powerful macro processor.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top