I am trying to define a debug_log function in a preprocessor #define in order for this function to exist only in Debug mode. The thing is that I wish to use a variable_argument function :
#ifdef DEBUG
#define DEBUG_ENABLED 1
#else
#define DEBUG_ENABLED 0
#endif
#define debug_log(msg, ...) \
do { \
if (DEBUG_ENABLED) { \
char str[300]; \
int length = -1; \
va_list argList; \
va_start( argList, msg ); \
length = vsnprintf(str, sizeof(str), msg, argList); \
va_end( argList ); \
if (length > 0) \
{ \
fprintf(stderr, "%s, %d ",__func__, __LINE__); \
fprintf(stderr, "%s", str); \
fprintf(stderr,"\n"); \
} \
} \
} while (0) \
The compiler is returning :
error: ‘va_start’ used in function with fixed args [build] 20 | va_start( argList, msg ); \
Thank you for your help ;)