Unexpected predefined macro behaviour when pasting tokens

前端 未结 3 718
囚心锁ツ
囚心锁ツ 2021-01-24 08:52

The following (test with gcc -E blah.c):

#define UNUSED(type) type UNUSED_ ## __COUNTER__
UNUSED(char const *)
UNUSED(int)

Generat

3条回答
  •  攒了一身酷
    2021-01-24 09:38

    Experimenting with gcc 4.4, this works:

    #define UNUSED(type) UNUSED_(type, __COUNTER__)
    #define UNUSED_(type, counter) UNUSED__(type, counter)
    #define UNUSED__(type, counter) type UNUSED_ ## counter
    UNUSED(char const *)
    UNUSED(int)
    

    But it doesn't work if I take out even one level of intermediates.

提交回复
热议问题