I am compiling with:
gcc 4.7.2 c89 I have the macro:
#define LOG_ERR(fmt, ...) \ fprintf(stderr, "[ERROR] %s:%d: error [%s] " fmt "\n", __func__, __LINE__, strerror(errno), ##__VA_ARGS__) And I am using it like this:
LOG_ERR("Failed to connect to message queue [ %d ]", msg_id); The fmt has been concatenated in the fprintf statement. How is this possible?
I tried to do the same with the following below (just to test the concept), but failed with a compile error:
/* Using char array */ const char name[] = "Joe"; printf("Hello how " name " how are you today?\n"); Using constant string literal const char *name = "Joe"; printf("Hello how " name " how are you today?\n"); Both gave me the following error:
expected ')' before name Thanks for any suggestions!