https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62228
Bug ID: 62228
Summary: gcc : expected identifier before numeric constant
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ankzzdev at gmail dot com
Created attachment 33379
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33379&action=edit
Header and C file used to reproduce this issue
I have attached the header file and c-code (t.c and t.h) used to reproduce this
issue.
# make t
cc t.c -o t
t.c: In function 'main':
t.c:8: error: expected identifier before numeric constant
make: *** [t] Error 1
Error is due to this piece of code in multi-line macro.
#define LOG(module, level, msg) \
if ( (module)->level ) \
msg_log(msg)
While verifying the pre-processed output of the c-code:
# gcc -E t.c
...
int main()
{
struct logger module;
if ( (&module)->0 ) msg_log("Ooops\n");
return 0;
}
# cat t.c
#include
#include "t.h"
int main()
{
struct logger module;
LOG(&module, 0, "Ooops\n");
return 0;
}
Here we can see the Macro LOG is wrongly getting interpreted.
LOG(&module, 0, "Ooops\n"); ==> if ( (&module)->0 ) msg_log("Ooops\n");
This is happening as "level" in macro is getting replaced with a value "0".
Leading to the issue: expected identifier before numeric constant