I want to make a simple macro that calls printf() twice like this
#ifdef ENABLE_DEBUGPRINTF
#define DEBUGPRINTF(msg) printf("At sim_time = %f:", sim_time); printf(msg);
#else
#define DEBUGPRINTF(msg) //evalutes to nothing
#endif
Now when I call
DEBUGPRINTF("Processed event type: %d with value %f\n", id, data)
It prints the first part "At sime_time = ... " correctly but the latter part where it says "Processed events ... " prints the value for id and data incorrectly.
Meanwhile
printf("Processed event type: %d with value %f\n", id, data);
Prints the values correctly.
When I try executing it by writing exactly out what I thought the macro would evaluate to, I have.
printf("At sim_time = %f:", sim_time); printf("Processed event type: %d with value %f\n", id, data);
This prints everything correctly! So why isn't my macro evaluating to this?