- 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
Admin
return (frist() ? CONDITION_FRIST : CONDITION_NOT_FRIST)
Admin
This seems like an obfuscated version of: #define FALSE TRUE
Admin
Thrid, but at least it's here: CONDITION_FILE_NOT_FOUND
Admin
To everything (tern tern tern) There is a season (tern tern tern) And a time to every purpose, under Heaven -- The Byrds, "Tern! Tern! Tern! (To Everything There Is A Season"
Clearly, the Byrds were IT soothsayers... :)
Addendum 2019-05-21 07:48: (formatting got messed up. fie!)
Admin
I am a meticulous man.
When throwing rocks at seabirds
I leave no tern unstoned.
Admin
Actually this is return true or return more true
Admin
QFMT
Admin
The true path to success: treat every failure like another success (at the very least the arrogance will irritate and frustrate your foes)
Admin
SMug .net developer checking in to say this would never happen in C# because it handles booleans sensibly
Admin
TRWTF is functions that return
bool
for success/failure. It's TRWTF because some people usetrue
for success, and some people usefalse
for success, and some, who are themselves TRWTF, usetrue
sometimes andfalse
other times.Admin
"Isn't that just the wrong way?"
"Yes, but /faster/!"
Admin
You are a mean bird-hater. When I leave no tern unstoned, it's because we were all sharing mushrooms.
Admin
Just a guess- could it be that 0 or 1 requires only 1 bit, but a 2 requires 2 bits? (a 1-bit overflow...)
Admin
I am also a conscientious man
When painting the arses of monkeys at the zoo
I leave no stern untoned.
Admin
So where's the punchline? What compiler flags caused the failure? Why/how did they cause it to fail?
Obviously this code is wrong but presumably it happened to work until a particular compiler flag was enabled or disabled which changed something about how booleans are handled.
Admin
Probably a flag about warnings on implicit casts. That would trigger on trying to return 1 or 2 as bool.
As a separate comment, if you ever find yourself doing #define RELATED_THINGA 1, #define RELATED_THINGB 2, #define RELATED_THINGC 5, etc., slap yourself and use an enum instead so you can have at least a little bit of type checking.
Admin
You are also a fine maker of puns. I can't compete with you, so I shall pass this tern.
Admin
In C++, conversion to bool changes zero to false, and anything non-zero to true. So (bool) (condition ? 1 : 2) will always return true, that's how the language is defined.
Admin
This is also the behaviour for C#, unless you have turned off the warnings about implicit conversions, or you set Option Strict On, which prevents implicit conversions.
Admin
https://tools.ietf.org/html/rfc2579#page-5
It's just a different definition of True and False...
Admin
I got some code today from a vendor and it has a nested ternary. I'm just waiting for the thing to explode.
Admin
Is there any language in which casting 2 to boolean would not return true?
Admin
Maybe boolean is also not a boolean, but rather #define bool int.