News for hackers. Stuff that matters.
Re:Clang is better than GCC by djur on Sunday November 27, 2022 @11:10PM (#33769734)
0 is the false value in C, no implicit casting or "truthiness" involved. The C standard explicitly defines if statements in terms of zero: "the first substatement is executed if the expression compares unequal to 0... [else] is executed if the expression compares equal to 0".

C does not have a boolean type. (The `true` and `false` defined in stdbool.h are macros expanding to the integer literals 1 and 0, respectively.)

Re:Clang is better than GCC by 3836293648 on Monday November 28, 2022 @02:42AM (#33770784)
C has a boolean type, it just doesn't have true and false constants in that type.
Re:Clang is better than GCC by pjmlp on Monday November 28, 2022 @04:04AM (#33771302)
C23 replaces them with proper keywords.
Re:Clang is better than GCC by djur on Monday November 28, 2022 @06:50PM (#33781617)
Yes, although they still evaluate to 0 and 1 and conditional logic is still defined in terms of 0 and 1. Maybe that will change at some point in the future as well!
Re:Clang is better than GCC by UncleEntity on Monday November 28, 2022 @08:51AM (#33773627)
They aren’t testing for ‘false’ in this case but for success.

Functions which return 0 on success I always compare with 0 as “if (foo()) error();” easily gets confusing. If I see “if (foo() != 0) error();” then I can easily tell what’s going on because C is funny like that.

Conversely, if I’m testing for truthfulness or NULL I’ll use the boolean operators.