Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use #if,#else,#endif... inside c macro

 #include < iostream >  

 #define MY_CHK_DEF(flag) \
 #ifdef (flag) \
    std::cout<<#flag<<std::endl; \
 #else \
    std::cout<<#flag<<" ,flag not define"<<std::endl; \
 #endif 


 int main()
 {
    MY_CHK_DEF(FLAG_1);
    MY_CHK_DEF(FLAG_2);
    MY_CHK_DEF(FLAG_3);
    ...  
 }

complier report:

main.cpp:3:24: error: '#' is not followed by a macro parameter

any ideas?

Thanks

like image 284
camino Avatar asked May 10 '11 06:05

camino


1 Answers

You actually can do this if you use BOOST processor header lib.. it provides a BOOST_PP_IF macro allow this type of decisions.

http://www.boost.org/doc/libs/1_53_0/libs/preprocessor/doc/ref/if.html

like image 140
Urkle Avatar answered Oct 06 '22 00:10

Urkle