Alex Rivera | Logout

The ## operator in C

Asked 2012-02-29T06:20:36.960
19

What does ## do in C?

Example:

typedef struct
{
    unsigned int bit0:1;
    unsigned int bit1:1;
    unsigned int bit2:1;
    unsigned int bit3:1;
    unsigned int bit4:1;
    unsigned int bit5:1;
    unsigned int bit6:1;
    unsigned int bit7:1;
} _io_reg;

#define REGISTER_BIT(rg,bt) ((volatile _io_reg*)&rg)->bit##bt

(I know what it all does besides the ## part.)

c
Edit
Report

1 Answer

9

The operator ## concatenates two arguments leaving no blank spaces between them:

#define glue(a,b) a ## b
glue(c,out) << "test";
answered 2012-02-29T06:23:38.767

Your Answer