The ## operator in C

后端 未结 7 2186
花落未央
花落未央 2020-12-06 17:02

What does ## do in C?

Example:

typedef struct
{
    unsigned int bit0:1;
    unsigned int bit1:1;
    unsigned int bit2:1;
    unsigned          


        
7条回答
  •  情书的邮戳
    2020-12-06 17:09

    It's called the pasting operator; it concatenates the text in bt with the text bit. So for example, if your macro invocation was

    REGISTER_BIT(x, 4)
    

    It would expand to

    ((volatile _io_reg*)&x)->bit4
    

    Without it, you couldn't put a macro argument directly beside text in the macro body, because then the text would touch the argument name and become part of the same token, and it'd become a different name.

提交回复
热议问题