On Feb 6, 2:09 am, William Ahern <will...@wilbur.25thandClement.com>
wrote:
> vipps...@gmail.com wrote:
> > On Feb 6, 12:40 am, "Tom?s ? h?ilidhe" <t...@lavabit.com> wrote:
> <snip>
> > > (Oh and by the way, I wouldn't use a macro such as ARRLEN(my_array)
> > > because then I'd have to worry about including the necessary header
> > > file... which is also the reason why I don't use NULL.)
> > NULL is declared in many standard C header files, among them is
> > <stdio.h>
> > I cannot believe you don't use NULL because you worry about it not
> > being defined.
>
> I don't use NULL 'cause I don't know to what it's defined. Usually the NULL
> macro expands to `0' or `(void *)0'. The former, typical on *BSD, needs to
> be cast when used from a comma expression and the return type of your
> function is a pointer, otherwise it might be evaluated as an int, which
> might not be wide enough if (sizeof int != sizeof (void *)).
I don't think that can happend.
>
> if (some_test_fails)
> return (errno = ESOMETHING), (void *)NULL;
As i said, NULL does not need to be casted here.
You don't need the comma operator either. the expression '(x, y, z)'
evaluates to the type of z with value z.
> Likewise, you have to cast it when passing as a vararg.
You have to cast 0 to (char *)0 too.
> execl("/bin/true", "true", (char *)NULL);
>
> Usually I just use an unadorned `0' in my code. I do this in part because,
> like the OP, I don't feel like including <stddef.h> or <stdio.h> or any
> other header that I don't need.
That in my opinion is very bad practise for a project.
> I comment my include statements to describe
> what I'm [trying] to import; it got really old doing:
>
> #include <stddef.h> /* NULL */
>
> But, to each his own. I don't know very many people who do this. I'm okay
> being alone 
Other programmers in your project might not be okay with that thought,
ask them first.
As for me, I wouldn't. Consider
--
char *p;
/* ... */
if(p == 0) /* did you really mean p == 0 or *p == 0 ? */
if(p == NULL) /* clearly ment p == NULL */
--