How to define macro function which support no input parameter and support also input parametr in the same time

前端 未结 4 1728
不知归路
不知归路 2021-01-15 22:12

I want to define a macro function which support at the same time:

1) No input parameter

2) Input parameters

some thing like that:

#de         


        
4条回答
  •  被撕碎了的回忆
    2021-01-15 22:28

    You can use sizeof for this purpose.

    Consider something like this:

    #define MACRO_TEST(X) { \
      int args[] = {X}; \
      printf("this is a test\n");\
      if(sizeof(args) > 0) \
        printf("%d\n",*args); \
    }
    

提交回复
热议问题