![]() ![]() ![]() 1 would work however, you don't actually need to call the _R version unless you're doing something recursive/complex. The _R variant macros expect an r argument that corresponds to macro sets (this is the first argument). The example below runs as expected, but it compiles with warnings from the MACRO expansion. Im trying to create a macro that handles them both. That Microsoft's CPP expands this isn't surprising MS's CPP is non-standard.Īs for the second question ( really should be a separate question though): My TLV structure can hold string or integer. If you want that to happen, you need an indirect macro (such as the one showed you). There's no step to back up and evaluate/expand FINAL. and now the CPP is done with BRACES, so it moves along further. BRACES however has two arguments, and is a two argument function-like macro, so it expands ( SPLIT's expansion is part of this expansion), leaving you with this: FINAL (1, 2, 3) Since you only have a function-like macro, nothing happens. This is then rescanned during rescan and further replacement during this step, FINAL is seen, but it doesn't have arguments after it. expands during argument substitution to: FINAL BRACES(1, SPLIT (2, 3)) ![]() Using the rules specified by the standard, your macro: START(FINAL, 1, (2, 3)) Can we change macro value in C You can’t. If the macro has parameters, they are substituted into the macro body during expansion thus, a C macro can mimic a C function. # define BOOST_PP_IIF_I(bit, t, f) BOOST_PP_IIF_ # bit(t, f) What is macro expansion in C The use of macro name with set of actual parameters is replaced by some code generated by its body. # define BOOST_PP_SEQ_FOR_EACH_I_R_DETAIL_CHECK_EXEC(r, macro, data, seq) BOOST_PP_FOR_ # r((macro, data, seq, 0, BOOST_PP_SEQ_SIZE(seq)), BOOST_PP_SEQ_FOR_EACH_I_P, BOOST_PP_SEQ_FOR_EACH_I_O, BOOST_PP_SEQ_FOR_EACH_I_M)Į:/dev-libs/boost/boost_1_60_0-mingw32/include/boost-1_60/boost/preprocessor/control/iif.hpp:32:31: note: in expansion of macro 'BOOST_PP_SEQ_FOR_EACH_I_R_DETAIL_CHECK_EXEC'Į:/dev-libs/boost/boost_1_60_0-mingw32/include/boost-1_60/boost/preprocessor/control/iif.hpp:25:39: note: in expansion of macro 'BOOST_PP_IIF_1' #define FINAL2(r, data, id, value) const char *p # id = #value īOOST_PP_SEQ_FOR_EACH_I_R(_, FINAL2, _, (a)(b)(c))Įrror output: $ g++ -I /e/dev-libs/boost/boost_1_60_0-mingw32/include/boost-1_60 -std=c++03 test2.cppĮ:/dev-libs/boost/boost_1_60_0-mingw32/include/boost-1_60/boost/preprocessor/seq/for_each_i.hpp:96:96: error: expected constructor, destructor, or type conversion before '(' token #define START(macro, a1, a2) macro BRACES(a1, SPLIT a2) I've faced with a strange problem while compiling very simple C++ program which leverages recursive macros expansion: #define FINAL(a1, a2, a3) const char *p = "final values are: " #a1 " " #a2 " " #a3 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |