Here there is a problem in code. First of all we need to understand
what a macro is.
#define name replacment_text
The name can have argumants also.
In this code. func(x) will be replaced by (x+x). But, you have used
(func)and it will be treated as a function call. You have provided a
declaration (extern int func(int);) for that function. So, it's
assuming that (func) is a function.
If you are expecting a macro to be used then
(func(10)) (10); to be used in your code. This will result (10+10) (10)
after preprocessing and which is syntactically incorrect.
(func(10))*(10); will give you the expected result.
Regards,
Raju
ju**********@yahoo.co.in wrote:
Consider the following piece of code:
$ cat a.c
extern int func(int);
#define func(i) (i+i)
int main(void)
{
(func)(10);
}
On preprocessing the above code,
$ cc -E a.c
# 1 "a.c"
extern int func(int);
main()
{
(func)(10);
}
-------------------------------------------------------------
func being a macro,(func)(10) should be expanded to (10+10)(10), but it
doesn't seem to. It is treated as a function.
Why is it so ?