groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stpecpy(): A better string copy function


From: Douglas McIlroy
Subject: Re: stpecpy(): A better string copy function
Date: Sun, 13 Feb 2022 21:28:02 -0500

>>>              if (!*dst)
>>
>> As I've noted elsewhere (can't remember if it's where you might have
>> seen it), I dislike punning pointers to Booleans.  But this is a matter
>> of style, and as far as I know nothing can go wrong with it.
>
> I wasn't punning the pointer to bool (which I also do a lot), but the
>  character.  An equivalent exanded version would be `if (*dst == '\0')`.

Even if it were a pointer, it would not be a pun. The C standard
defines if(e), where e is an expression, to switch on the value of
(e)!=0. If e is a pointer, 0 is converted to the null pointer.

(As a matter of programming style, I prefer to use 0 to specify a null
pointer; it doesn't require one to haul in stddef.h as NULL does. And
it doesn't shout.)

Doug



reply via email to

[Prev in Thread] Current Thread [Next in Thread]