This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A question about macro replacement


zhao_bingfeng@topsec.com.cn wrote:
With following code:
[CODE]
struct B {
	int c;
	int d;
};

#define X(a, b, c) \
do\
{\
	if (a)\
		printf("%d, %d\n", b.c, c);\
	else\
		printf("%d\n", c);\
}while(0);
[/CODE]

Why
	int d = 24;
	X(1, b, d);
can be compiled successfully but
	X(1, b, 24);
not.

I cannot find any description about this behavior in C standard.

Well, with the X(1, b, 24) case, the b.c in the first printf line becomes b.24, which is obviously a syntax error.


This sort of thing would be a fair bit easier to track down if you quoted the error message rather than just saying that it cannot be compiled successfully.

- Brooks


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]