another bug in /lib/cpp?

Tom Tkacik tkacik at rphroy.UUCP
Thu Oct 12 11:18:46 AEST 1989


I found another reason to use gcc-cpp instead of /lib/cpp.
/lib/cpp will expand a macro with arguments even if none are given. (HuH?)

For example:

#define min(a,b)  ((a)<(b)?(a):(b))

f()
{
	int min;

	return min;
}

In the function f(), min should not be expanded because it is not followed
by parenthesis.  However, cpp on the 3b1 tries to expand it anyway with
the error messages 

junk.c: 5: min: argument mismatch
junk.c: 7: min: argument mismatch
junk.c: 7: min: unterminated macro call

Gcc-cpp gets this right.  K&R1 say this is legal.
No fair telling me I should not do this, I know that :-)
-- 
---
Tom Tkacik		GM Research Labs,   Warren MI  48090
uunet!edsews!rphroy!megatron!tkacik		Work Ph: (313)986-1442
"If you can't stand the bugs, stay out of the roach-motel."  Ron Guilmette



More information about the Unix-pc.general mailing list