How can I generate unique values in the C preprocessor?

后端 未结 6 1174
南笙
南笙 2020-11-27 04:54

I\'m writing a bunch of related preprocessor macros, one of which generates labels which the other one jumps to. I use them in this fashion:

MAKE_FUNNY_JUMPI         


        
6条回答
  •  没有蜡笔的小新
    2020-11-27 05:30

    I can't think of a way to automatically generate them but you could pass a parameter to MAKE_LABEL:

    #define MAKE_LABEL(n) my_cool_label_##n:
    

    Then...

    MAKE_FUNNY_JUMPING_LOOP(
      MAKE_LABEL(0);
      MAKE_LABEL(1);
    )
    

提交回复
热议问题