This one bit me today

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Fri Oct 6 01:17:54 AEST 1989


In article <2432 at hub.UUCP>, dougp at voodoo.ucsb.edu writes:

|    int a=1,b=2,*p=&a,c;
|    c=b/*p;

|  
|  First real flaw in the C grammer I have found.

  This is a good example, and I thank you. I have added something
similar to my list of things to think about in the pointers section of
my C course notes.

  It pops up in macros from time to time. Consider:
	#define xavg(m) (sum+3)/m
Macros like this work fine until someone makes the arg a pointer deref,
in which case the compiler screams and the programmer can't see the
error. It's even worse if someone makes a mistake like this in a system
header file...
	Kruft = xavg(*misc_err)+2;
or even worse
	Kruft = xavg(*misc_err)+2 /* ruft constant */;
which gives no warning but a wrong answer.
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon



More information about the Comp.lang.c mailing list