5

I just found out, there is a GCC flag that prevents you from using integers in a bool context in C.
Like wtf?!
Not only is this the original "bool" implementation of C, but it's also a widespread concept for use in NULL checks and the likes.

Comments
  • 1
    I can buy it though. It will rely on an implicit to make that happen, so using a more strict boolean type probably pays dividends if you have enough int -> bool conversions.
  • 0
    @RocketSurgeon
    Largely that it's automatically activated with -Wall, despite essential blocking a standard specified feature.
  • 7
    @metamourge Uh? I'm using -Wall -Wextra and no bool type in C all the time.

    My general coding convention is to compare explicitely with NULL, 0 or '\0' depending on which kind of comparison I'm making.

    But I compare integers to 0 explicitely only if the 0 is meant as countable quantity, not as logical state like e.g. a flag.
  • 2
    -Wall actually means -Wsome
  • 2
    It's not a big deal, the goal is to minimize implicit conversion. It's not there because It's "bad" but to explicitely warn the user "hey, Im doing some automated work here that you didn't explicitely tell me to do, just so you know"

    More options is never a bad thing, I'd be more worried if there was a lack of options in gcc, but there isn't!
Add Comment