I am unable to understand how the preprocessor works and what does the ##
stands for in this particular example
#include <stdio.h>
#define TEMP_KEY(type,Key) (TEMP_##type | Key)
enum TEMPKey_Type
{
TEMP_UNKNOWN = 0,
TEMP_SPECIAL ,
TEMP_UNICODE
};
enum Actual_Key
{
TEMP_RIGHT = TEMP_KEY(UNKNOWN,0x1),
TEMP_LEFT = TEMP_KEY(SPECIAL,0x1),
TEMP_UP = TEMP_KEY(UNICODE,0x1)
};
int main()
{
printf("\n Value of TEMP_RIGHT : %d ",TEMP_RIGHT);
printf("\n Value of TEMP_LEFT : %d ",TEMP_LEFT);
printf("\n Value of TEMP_UP : %d ",TEMP_UP);
return 0;
}
How does this
#define TEMP_KEY(type,Key) (TEMP_##type | Key)
work or how and what exactly is TEMP_##type
replaced by during preprocessing?
The "##" means concatenate. Therefore
TEMP_RIGHT = TEMP_KEY(UNKNOWN,0x1)
becomesTEMP_RIGHT = TEMP_UNKNOWN | 0x1,
("TEMP_" and "UNKNOWN" are joined together)