Bug 62228 - gcc : expected identifier before numeric constant
Summary: gcc : expected identifier before numeric constant
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-22 11:40 UTC by Ankzz
Modified: 2014-08-22 12:40 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Header and C file used to reproduce this issue (385 bytes, application/x-compressed-tar)
2014-08-22 11:40 UTC, Ankzz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ankzz 2014-08-22 11:40:58 UTC
Created attachment 33379 [details]
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 <stdio.h>

#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
Comment 1 Marek Polacek 2014-08-22 12:01:02 UTC
Huh?  Why do you think it is a bug?
Comment 2 Ankzz 2014-08-22 12:33:16 UTC
Why do you think its not a bug?

It would be better if you can explain me the reason why level should be replaced with a "0".

In the same macro if I replace "level" with "_level", 

#define LOG(module, level, msg) \
    if ( (module)->_level ) \
    msg_log(msg)

I get the pre-processed code as :

    if ( (&module)->_level ) msg_log("Ooops\n");
Comment 3 Ankzz 2014-08-22 12:40:21 UTC
(In reply to Marek Polacek from comment #1)
> Huh?  Why do you think it is a bug?

Got it ... Yup .. its not a bug. I would mark it resolved.