- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Edit Admin
But at least they future-proofed
convert_compare_resultby having it print an error message if called with an unimplemented member of their enum. Surely everywhere else in their codebase has thatprintf()directed to a log of some kind and surely all their admins and customers' admins always read and act on every log entry.Surely?
Admin
As a truly antique C programmer, I think the enum definition and its use in the function declaration don't seem to match. With "typedef enum exop_t { ... };", an "enum exop_t" is declared, but no type is defined (i. e., this won't compile, the "typedef" needs to be removed). In order for "static bool compare_booleans (bool bool1, bool bool2, exop_t exop)" and "static boolean convert_compare_result (int32_t cmpresult, exop_t exop)" to work, the declaration should be "typedef enum { ... } exop_t;". I won't comment on the suggestion of leaving the "_t" suffix to POSIX datatypes - you souldn't use them in your custom code. And finally, the printf() call should be a "fprintf(stderr, ...)" to address the standard error output, and maybe contain something helpful. Okay, I'm old, and I'll show myself out...
Admin
I suspect the problem came from using non booleans as booleans, e.g. comparing two ints for their truthiness. I cannot explain the enum operations. Smells like over-engineering.
Which makes me think: were these really C programmers? Because they would use a boolean (*exop)(int32_t).
Edit Admin
I'm having my breakfast and this code made me nauseous and difficult to finish eating.
Edit Admin
This line:
if ((bool1 && bool2) || (!bool1 && !bool2)) {is just
if ( bool1 != bool2 ).Well, unless they've done something über-stupid like defining their own
boolas something other than_Stdbool. See, the thing is,_Stdboolis just a weird name for what amounts to C++'sbool, and, except in the UB-inducing case of one that hasn't been initialised yet, it is, like the one in C++, constrained by the language to be eitherfalse(0) ortrue(1).However, there's a substantial anonymisation fail, one that makes me suspect that the original code isn't in C (nor in C++), but perhaps Java. Consider this definition:
(all decorated with lovely
bools) and this one:which returns
booleaninstead.Or they've defined their own
booleanalongside C99+'sbool==_Stdbool, which is definitely a WTF by itself.But yeah, the whole thing is a WTF, what amounts to a low-quality partial reimplementation of C++20+'s spaceship operator (
operator <=>) without the automatic selection (by the compiler) of how to use its return.Addendum 2025-10-28 08:29: Ugh, no, it's
if ( bool1 == bool2 )Edit Admin
Not Java, at least not that code. The 'typedef enum' is a dead giveaway it's C or C++.
Edit Admin
I don't believe the frist line of the article. Were booleans really ever "frustrating"? If you didn't like using 1 and 0, it was trivial to use
And if you have a variable that might not be 1 or 0 and you want to test it for truthiness, we all knew the idiom
!!variable. You didn't even need this inifstatements.The closest to frustration might have been inconsistent styles.
Admin
TRWTF is that they didn't handle FILE_NOT_FOUND
Edit Admin
Or that it has been anonymised into C/C++. But badly.
Admin
Okay, this is an over-engineered solution for a non-existent problem, but how and why was dealing with logical values problematic before stdbool? It way always clearly defined that zero means 'no/false' and non-zero means 'yes/true'. Also comparison and logical operators always return 1 for true.