How to define a define in C?

后端 未结 2 372
星月不相逢
星月不相逢 2021-01-17 10:16

Is it possible to write a #define that defines a #define?

For example:

#define FID_STRS(x) #x
#define FID_STRE(x) FID_STRS(         


        
相关标签:
2条回答
  • 2021-01-17 10:52

    No; preprocessing is performed in a single pass. If you want or need more advanced behavior, consider using another tool to preprocess the source, like m4.

    Further, the # in the replacement list (at the beginning of #define FIDN... would be parsed as the # (stringize) operator: the operand of this operator must be a named macro parameter, which define is not.

    0 讨论(0)
  • 2021-01-17 10:59

    No while defining macros u should take care of one thing that macro should not call itself (reccursively) either directly or indirectly.

    I know two static variables consuming 8 bytes will be expansive for u.

    I have solution over it

    #define FID_STRS2(x) #x
    #define FID_STRE(x) FID_STRS2(x)
    #define FID_DECL(n, v) static int FIDN_##n = v;static const char *FIDS_##n = FID_STRE(v)
    

    Just rename them going reccursive

    0 讨论(0)
提交回复
热议问题