This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
question on Multiple level macro expansion
- From: Qing Zhao <qing dot zhao at oracle dot com>
- To: polacek at redhat dot com, joseph at codesourcery dot com
- Cc: gcc Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 27 Sep 2019 16:06:02 -0500
- Subject: question on Multiple level macro expansion
Hi,
GCC cannot compile the following small testing case:
[qinzhao@localhost]$ cat t1.c
extern void boo (void *addr);
#define foo(addr) \
boo (addr)
#define bar(instr, addr) \
(instr) (addr)
void check (void *addr)
{
bar(foo, addr);
}
[qinzhao@localhost]$ sh t
/home/qinzhao/Install/latest/bin/gcc -O -S t1.c
t1.c: In function ‘check’:
t1.c:11:7: error: ‘foo’ undeclared (first use in this function); did you mean ‘boo’?
11 | bar(foo, addr);
| ^~~
t1.c:7:4: note: in definition of macro ‘bar’
7 | (instr) (addr)
| ^~~~~
t1.c:11:7: note: each undeclared identifier is reported only once for each function it appears in
11 | bar(foo, addr);
| ^~~
t1.c:7:4: note: in definition of macro ‘bar’
7 | (instr) (addr)
| ^~~~~
However, if I delete the parantheses from the macro bar as following:
#define bar(instr, addr) \
instr (addr)
The compilation succeed.
also icc can successfully compile the original small testing case.
My question is:
is this a bug for GCC?
or this is a coding error?
thanks a lot for your help.
Qing