Using macros to include `stddef.h` from GCC version directory

Viewed 38

I'm trying to include stddef.h from GCC folder according to the system version. Using the next sequence of macros:

#define __gcc_header(x) #x
#define _gcc_header(x) __gcc_header(/usr/lib/gcc/x86_64-redhat-linux/#x/include/stddef.h)
#define gcc_header(x) _gcc_header(x)
#include gcc_header(__GNUC__)

I got the next error:

fatal error: /usr/lib/gcc/x86_64-redhat-linux/\"11\"/include/stddef.h: No such file or directory
    4 | #include gcc_header(__GNUC__)
      |                             ^
compilation terminated.
1 Answers

Thanks to @Eric Postpischil, the solution is to use the macros like:

#define __gcc_header(x) #x
#define _gcc_header(x) __gcc_header(/usr/lib/gcc/x86_64-redhat-linux/x/include/stddef.h)
#define gcc_header(x) _gcc_header(x)
#include gcc_header(__GNUC__)
Related