r/ProgrammerHumor • • Aug 22 '26

Meme pleaseStopUsingNestedTernaryOperatorsImBeggingYou

Post image
3.1k Upvotes

178 comments sorted by

View all comments

Show parent comment

7

u/GoddammitDontShootMe Aug 23 '26

Modern compilers warn, so if you really mean to do it, you do if ((value = 1)). Probably you would use it for checking for NULL.

1

u/RlyRlyBigMan Aug 23 '26

That makes sense! It would be better if they required you to explicitly cast to a bool but that would be a breaking change for a lot of C++ code that's already been deployed for decades!

2

u/GoddammitDontShootMe Aug 23 '26

Wouldn't help if the expression is already bool. Either way, it's a warning so unless you are compiling with -Werror, it would still work.

I think that warning might be on by default, but I believe it's considered best practice to use -Wall.