Arif Ahmet Balık February 2016

What is '##' in C?

I'm using USART in Keil and I saw this;

#define USART_DRV_NUM 6

#define USART_BAUDRATE 9600

#define _USART_Driver_(n) Driver_USART##n
#define USART_Driver_(n) _USART_Driver_(n)

extern ARM_DRIVER_USART USART_Driver_(USART_DRV_NUM);
#define ptrUSART (&USART_Driver_(USART_DRV_NUM))

Here is the thing;

#define _USART_Driver_(n) Driver_USART##n

I couldn't find any examples on the Internet. Does anyone know something about this thing?

Answers


iharob February 2016

It's called Token Pasting Operator. It generates an identifier for example

#define _USART_Driver_(n) Driver_USART##n

int _USART_Driver_(_EXAMPLE);

is translated to

int Driver_USART_EXAMPLE;

Note that, n is not a variable. It's replaced literally before actual compilation in the prepropcessing stage.

Post Status

Asked in February 2016
Viewed 1,974 times
Voted 4
Answered 1 times

Search




Leave an answer