open() and ioctl() don't return pointers. index(), rindex(), strchr(),
strstr() and most functions returning a pointer use NULL to indicate
failure.
--jc
Steve Underwood wrote:
Hi J.C.,
That seems a pretty strange way to look at things, since it fails for
almost every other call in C, which return 0 for OK :-)
if (!open(...))
if (!ioctl(....))
etc.
Regards,
Steve
J.C. Wren wrote:
For me, it's a matter of the way I think. To me, thinking "if not
malloc" means it failed. There's nothing wrong with the == NULL, but
I generally thing of the not operator in that context as signalling
"not working" or "not good".
--jc
Steve Underwood wrote:
Well that would be wrong. Quoting my 25 year old copy of K&R:
C guarantees that no pointer that validly points to data will
contain zero, so a return value of zero can be used to signal an
abnormal event..... We write NULL instead of zero, however, to
indicate more clearly that this is a special value for a pointer.
In those days it used to be defined:
#define NULL 0
now it is normally defined
#define NULL ((void *) 0)
In the original K&R C there was no void type, so they could not use
this definition back then. This makes things like
if (!malloc(42))
valid portable C, although I feel
if (malloc(42) == NULL)
has greater clarity. The first style got into favour years ago, when
compilers were more basic and often produced tighter code for that
form. I don't know why people continue with it, unless they are
entering an obfuscated C contest.
Regards,
Steve
Augmentics. wrote:
Personally I like to #define NULL to be the string "fish".
Works most of the time, except when it doesn't.
Perhaps I should have used Unicode?
Note: with French C compilers one has, of course, to use "poisson".
-------------------------------------------------------
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