TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Robin Sheppard
from: Darin McBride
date: 1998-08-17 20:05:38
subject: NULL pointers

KK> CONFIG *c;
 KK> if(!c)

 RS>    Is testing for a 'false pointer', ie, using the logical NOT operator 
 RS>    like you did above ANSI standard?  I know that different compilers 

Yup.  NULL is defined to be equal to (void*)0.  The bit pattern is not
necessarily all 0's, but it will compare equal to a constant of (void*)0.

 RS>    I'm just wondwering whether using this shortcut will compromise code 
 RS>    portability- if not, I'll save typing "!=NULL" from
now on.  :>

No compromise on portability, but, IMNSHO, a huge compromise in
readability.  I recommend only using if (!b) or if (b) if b is boolean, if
b is a pointer always compare against NULL, and if b is an integer, always
compare against zero.  Much more readable, IMO.  The generated code will
always be the same, but the written code is much easier to understand.


---
* Origin: Tanktalus' Tower BBS (1:250/102)
SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728 810
SEEN-BY: 639/252 670/213 218
@PATH: 250/102 201 99 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.