Hello,
I have a variable argument function which prints error messages in my application,whose code is given below.
void error(char *format,...)
{ va_list args;
printf("Error: ");
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
printf("\n");
abort();
}
This function error()is used in error conditions as follows:
error("invalid image width %d and image height %d in GIF file %s",wid,hei,name);
Function error() is called from Different places with different arguments(Variable argument function).
Function approach works fine.
Now if i have to make this function error() as a macro, how do i do it. I tried doing as:
#define error(format) {va_list args;\
printf("Error: ");\
va_start(args, format);\
vfprintf(stderr, format, args);\
va_end(args);\
printf("\n"); abort()}
But this does not print the arguments correctly.
What is wrong in the macro definition above.
What is the fix?
Thank you.
-AD