Liste des Groupes | Revenir à cl c |
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!
Les messages affichés proviennent d'usenet.