Possible bug in cpp
Jonathan Ryshpan
jon@berkeley.innomedia.com
Mon May 1 17:49:00 GMT 2000
I'm trying to build a debugging macro which will emit the file and line number
along with other things I want to print; and am having a little trouble. I've
located the problem in cpp, but don't know whether it's my fault or a bug.
The difficulty is that in the example below cpp eats __LINE__ when there are
no arguments to PRINTD() macro, but everything works fine if there is at
least one argument.
Here's the id info for the cpp that I'm running:
======================= Info Starts =======================
$ /lib/cpp -v
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/i386-redhat-linux/include
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
/usr/include
End of search list.
======================= Info Ends =======================
Here are the two input files:
======================= debug.h Starts =======================
# define PRINTD(fmt, args...) fprintf(stderr, "%s:%d - " fmt, __FILE__, __LINE__, ## args)
======================= debug.h Ends =======================
======================= test-debug.c Starts =======================
#include <stdio.h>
#include "debug.h"
main(argc, argv)
{
printf("This is a test\n");
PRINTD("Error\n");
PRINTD("Error-1\n", 1);
return 0;
}
======================= test-debug.c Ends =======================
$ cc -E test-debug.c
produces output ending with:
======================= Output Starts =======================
...
# 1 "test-debug.c" 2
# 1 "debug.h" 1
# 2 "test-debug.c" 2
main(argc, argv)
{
printf("This is a test\n");
fprintf(stderr, "%s:%d - " "Error\n" , "test-debug.c", ) ;
fprintf(stderr, "%s:%d - " "Error-1\n" , "test-debug.c", 8,1 ) ;
return 0;
}
======================= Output Ends =======================
More information about the Gcc-bugs
mailing list