Sujet : Re: question about nullptr
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 09. Jul 2024, 03:49:49
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240708194600.781@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-07-08, Michael S <
already5chosen@yahoo.com> wrote:
On Sun, 07 Jul 2024 15:17:34 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>
I just about always use NULL, not 0, when I want a null pointer
constant. Similarly, I use '\0', not 0, when I want a null character,
0.0 when I want a floating-point zero, and false when I want a Boolean
zero. I just like being explicit.
>
Pointer: I very rarely use NULL.
Character: I never use '\0'.
Floating point: I never use 0.0.
Never say never!
printf("%f\n", 0); // undefined behavior.
printf("%f\n", 0.0); // correct
If you're #define-ing a floating-point constant that has
no fractional part, you should put that .0 there.
Someone's going to pass your constant as a variadic argument,
where it doesn't convert to floating-point.
Also:
1/3 -> 0
1/3.0 -> 0.33333...
If you're #define-ing a floating point constant that has
no fractional part, and don't include the .0, and the
programmer uses it as a division denominator thinking that
it's a floating-point quantity, oops!
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca