[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
- Fwd: stpecpy(): A better string copy function, Alejandro Colomar (man-pages), 2022/02/13
- Fwd: Re: stpecpy(): A better string copy function, Alejandro Colomar (man-pages), 2022/02/13
- Re: Fwd: Re: stpecpy(): A better string copy function, Alejandro Colomar (man-pages), 2022/02/13
- Re: Fwd: Re: stpecpy(): A better string copy function, Alejandro Colomar (man-pages), 2022/02/13
- memccpy(3) and stpcpy(3) status in C2x (was: stpecpy(): A better string copy function), Alejandro Colomar (man-pages), 2022/02/13
- Re: memccpy(3) and stpcpy(3) status in C2x (was: stpecpy(): A better string copy function), Martin Sebor, 2022/02/14
- Re: memccpy(3) and stpcpy(3) status in C2x (was: stpecpy(): A better string copy function), Steffen Nurpmeso, 2022/02/14
- Re: stpecpy(): A better string copy function (was: memccpy(3) and stpcpy(3) status in C2x), Alejandro Colomar (man-pages), 2022/02/14
- Re: stpecpy(): A better string copy function,
Douglas McIlroy <=