Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a macro for C/C++ #include

I work on AS/400 which is sometimes non-POSIX. We also need to compile our code on UNIX. We have an issue with something as simple as #include.

On AS/400, we need to write:

#include "*LIBL/H/MYLIB"

On UNIX, we need to write

#include "MYLIB.H"

At the moment we have this (ugly) block at the top of each C/C++ file:

#ifndef IS_AS400
    #include "*LIBL/H/MYLIB"
    /* others here */
#else
    #include "MYLIB.H"
    /* others here */
#endif

We would like a unified macro. Is this possible? I don't know how to write it.

Ideally, the resulting syntax would be:

SAFE_INCLUDE("MYLIB")
that would expand correctly on each platform.

Please advise.

like image 814
kevinarpe Avatar asked Dec 07 '22 20:12

kevinarpe


1 Answers

You can simply #include some separate header in every of your source files containing that ugly #ifndef just once. It's a common practice anyway.

like image 65
unkulunkulu Avatar answered Dec 26 '22 05:12

unkulunkulu