David Robinson wrote: > > On Mon, 1 Jul 1996, Robert S. Thau wrote: > > /* > > * Also, test pointers > > * against NULL, i.e. use: > > * > > * (p = f()) == NULL > > * not: > > * !(p = f()) > > */ > > !foo is used all over the current Apache code. > > This is one that really irritates me (perhaps almost as much as my > comment style irritates rst 8-( ) because to my mind, '!' takes a boolean > argument, not a pointer. (Reasons below.) > > But, amazingly, I _can_ actually understand what is meant here. > Am I the only person who thinks that this discussion has turned into a > complete waste of time? > > David. > > Why (!p) is wrong > ----------------- > > As I understand C, > char *p; > > if (!p) ... > > is equivalent to > if (!(int)p) ... > > Which seems to me to mean something quite different to > if (p != NULL) ... Your understanding is lacking. To quote K&R: "The operand of the ! operator must have arithmetic type or be a pointer". > > In particular what happens when sizeof(char *) > sizeof(int) > e.g. Cray or Digital UNIX, or when NULL != (void *)0 (maybe on some > microsoft systems) ? Also quoting K&R: "The symbolic constant NULL is often used in place of zero". > > Even if in practice the two test are likely to evaulate to the same > answer, it does seem like sloppy programming to me. > > Cheers, Ben. -- Ben Laurie Phone: +44 (181) 994 6435 Freelance Consultant and Fax: +44 (181) 994 6472 Technical Director Email: ben@algroup.co.uk A.L. Digital Ltd, URL: http://www.algroup.co.uk London, England.