[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Findutils-patches] [PATCH] Include sys/stat.h in files where we use
From: |
Eric Blake-1 |
Subject: |
Re: [Findutils-patches] [PATCH] Include sys/stat.h in files where we use struct stat. |
Date: |
Tue, 26 Jun 2007 14:37:58 -0700 (PDT) |
> My opinion here is, of course, not of value but I also always prefer 0
> over '\0' in C code for similar reasons. However I also always prefer
> 0 over NULL too. :-) Zero is one of the few magic numbers and I
> prefer not seeing it obfuscated with a macro.
But that is bug-prone.
Consider:
printf("%p%d", NULL, 1);
vs.
printf("%p%d", 0, 1);
On a 32-bit platform, it works. On a 64-bit platform, it fails.
Using NULL consistently prevents bugs like this, because
unlike 0, the named constant NULL also conveys type
information. Yes, 'gcc -Wall' will tell you about this
particular example, but I find it easier to use a named
constant than to risk this type of bug.
Another reason to prefer NULL when a pointer is intended
is due to function overloading in C++, where foo(0) and
foo(NULL) could invoke different code paths.
--
Eric Blake
--
View this message in context:
http://www.nabble.com/Re%3A--Findutils-patches---PATCH--Include-sys-stat.h-in-files-where-we-use-struct-stat.-tf3981017.html#a11314399
Sent from the GNU - FindUtils - Patches mailing list archive at Nabble.com.