I have the below program. It passes a macro as optional arg to variadic function. Within that function definition, shall we able to get that macro without expansion. I have used type as 'char *' and is showing the macro expanded string. Any ways to get macro as it is.
#include <stdio.h>
#include <stdarg.h>
#define CONN_DISALLOW 3201008
#define SYSLOG_CONN_DISALLOW \
"%d: Disallowing new connections. Reason: %s.\n", CONN_DISALLOW
void cp_syslog(int syslogid, ...);
void cp_syslog(int syslogid, ...)
{
char *syslog_disallow;
va_list ap;
va_start(ap, syslogid);
syslog_disallow = va_arg(ap, char *);
printf("String is %s", syslog_disallow);
printf("Macro is %s", SYSLOG_CONN_DISALLOW);
va_end(ap);
}
int main()
{
int id = 2;
cp_syslog(id, SYSLOG_CONN_DISALLOW);
return 0;
}
Now got the output as:
String is %d: Disallowing new connections. Reason: %s.
Macro is %d: Disallowing new connections. Reason: %s.
Expecting as:
String is SYSLOG_CONN_DISALLOW
My expectation here is how to process a particular macro if different macros are passed as optional argument to the same variadic func.
like below:
cp_syslog(id, SYSLOG_CONN_DISALLOW);
cp_syslog(id, SYSLOG_CONN_ALLOW);
cp_syslog(id, SYSLOG_ICMP_DISALLOW);