A clever approach to macro definition in C

  • 2020-06-12 10:09:13
  • OfStack

Recently, I took a look at the intel driver in the linux kernel and learned a useful tip, as follows:


#define IN
#define OUT
#define UAdress volatile unsigned int *
#define Raw_buffer void *
void SetHwiPortsDataReg(IN UAdress Register , IN int value)
{
 _SetHwiPortsDataReg(Register,&value);
}
 
void _Out_Put_value(IN UAdress Register, OUT Raw_buffer buffer)
{
 _Out_Put_value(Register,buffer);
}

Here, the definitions of IN and OUT make the code easier to read. As mentioned, IN stands for input and OUT for fetch, a small trick.

conclusion


Related articles: