Being faced with the question whether it s possible to choose #include
s in the preprocessor I immediately thought not possible.
.. Only to later find out that it is indeed possible and you only need to watch out for argument expansions (which e.g. Boost.Preprocessor can take care of).
While I d avoid actually doing that for includes if possible, I d like to know why this works. At the moment I fail to get a useful understanding in the C++ or C standard.
Are parameterized macros allowed for any preprocessor-directive? (except #define
/#undef
)
Can someone reference where this is allowed and summarize it?
Example for the curious utilizing Boost.Preprocessor for simplicity:
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>
#define INC_LOCAL(a,b) BOOST_PP_STRINGIZE(BOOST_PP_CAT(BOOST_PP_CAT(a,b),.h))
#define INC_GLOBAL(a,b) BOOST_PP_CAT(BOOST_PP_CAT(<,a),BOOST_PP_CAT(b,>))
#include INC_LOCAL(loc,al) // #include "local.h"
#include INC_GLOBAL(vect,or) // #include <vector>
Update: Referenced C standard, clarified question.