how can I avoid the use of #if in a polymorphic print macro

后端 未结 4 710
终归单人心
终归单人心 2021-01-26 11:41

Let\'s try to run the following code:

#include 
#define MY_MACRO1(isArray,y) do { \\
                      if(isArray) \\
                                 


        
4条回答
  •  死守一世寂寞
    2021-01-26 12:45

    Let me first say that I don't think you should use macro for this. You should have 2 separate functions instead, with possibly additional _Generic expression as shown in Lundins answer.

    However, it is possible to do with multiple macro defines:

    #define MY_MACRO(isArray,y) MY_MACRO_ ## isArray (y)
    #define MY_MACRO_0(y) printf("%d", y)
    #define MY_MACRO_1(y) printf("%d", y[0])
    

提交回复
热议问题