0

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?

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67

1 Answers1

1

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.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97