Tuesday, 6 August 2013

How do I limit the scope of the preprocessing definitions used?

How do I limit the scope of the preprocessing definitions used?

How do I preprocess a code base using the clang (or gcc) preprocessor
while limiting its text processing to use only #define entries from a
single header file?
This is useful generally: imagine you want to preview the immediate result
of some macros that you are currently working on… without having all the
clutter that results from the mountain of includes inherent to C.
Imagine a case, where there are macros that yield a backward compatible
call or an up-to-date one based on feature availability.
#if __has_feature(XYZ)
# define JX_FOO(_o) new_foo(_o)
# define JX_BAR(_o) // nop
...
#else
# define JX_FOO(_o) old_foo(_o)
# define JX_BAR(_o) old_bar(_o)
...

No comments:

Post a Comment