Hi, > Which is a really bad programming practice. After all, ain't unary > logical operations with pointers illegal? Better way would be: > > if (foo == NULL)
as far as i know the compiler does if(!foo) => if(0==foo) =>if(NULL==foo) at compile time. But generally it's not possible to compare a pointer with an integer, because they the have diffent type and often do not have the same size. On sparc64 the user-space pointer have 32 bit while the kernel-space pointers have 64 bit, so on that platform comparing integers with pointers is a bad idea. Therefore gcc generally produces a warning if he finds such ugly code. >> After all, ain't unary logical operations with pointers illegal? A pointer is an object of size sizeof(pointer); there is no reason why not to apply logical operations with that object. > I've been reading the responses, and it drove me to one of the > many C FAQ's that are out on the net -- I've bought the book. Some Questions and Answers are only there. The FAQs are for C90 but nearly all of it allpies also for C99. The C99 can be bought for $18 at www.ansi.org; you get it in a minute in pdf format ;-) Rolf F. ------------------------------------------------------------------------------------- mspgcc-users@lists.sourceforge.net schrieb am 27.03.04 13:50:47: > > Hey folks, > > Russell Nelson wrote: > > Even if there was a good reason to change it, there's way too > > much code that does this kind of thing: > > > > foo = malloc(10); if (!foo) exit(1); > > Which is a really bad programming practice. After all, ain't unary > logical operations with pointers illegal? Better way would be: > > if (foo == NULL) > > Which gives nice int value to if for evaluation in C (bool in C++). > > Indrek > > -- > Indrek Rebane | Borthwick-Pignon > Electronics Engineer | Tartu Science Park > Phone: (+372) 7 302 641 | Riia 185, 51014 Tartu > Fax: (+372) 7 383 041 | Estonia > ind...@bps.co.ee | www.bps.co.ee > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users