Given the following code:
#define MY_STRINGIFY_MACRO(...) #__VA_ARGS__ #define PORT_MAC(portNum) port: portNum #define LOG_MACRO(...) printf( MY_STRINGIFY_MACRO(__VA_ARGS__) ) void func(int portNum) { LOG_MACRO( PORT_MAC(portNum) ); /* In a more general way I would use this macro as LOG_MACRO( PORT_MAC(portNum), PORT_MAC(portNum1) ... ); to get output of " port: 2, port: 3 ... "*/ } When func() is called with a port number, for example 2, the output is:
port: portNum instead of
port: 2 And if I use the macro the following way:
LOG_MACRO( PORT_MAC(2) ); Then I get the desired output:
port: 2 How can I fix my code so that it could handle both cases and the output will always contain the portNum value?