News for hackers. Stuff that matters.
Re:Let’s Stop Bashing C by mining on Friday December 02, 2016 @12:05PM (#13090287)
This is completely false, it compiles in C++ fine. Are you thinking of Java?
Re:Let’s Stop Bashing C by user5994461 on Friday December 02, 2016 @12:14PM (#13090373)
Well, it shouldn't. It's possible that you have to give a flag to the compiler to error on that kind of implicit casting. It should at least give a warning for sure.

I am definitely talking about C++

Re:Let’s Stop Bashing C by tomlx on Friday December 02, 2016 @01:04PM (#13090809)
Compiles fine with -Wall -Werror. No warnings.
Re:Let’s Stop Bashing C by user5994461 on Friday December 02, 2016 @05:57PM (#13093062)

    int x = 1;
    bool y = x;

    # cl.exe /W3 main.c
This code gives a warning on VS2012. But it doesn't give one when the cast is in a loop condition. That is weird.

http://stackoverflow.com/a/31552168/5994461

This stackoverflow message talks about the specs for C11, and the first comment adds information on the C++03 spec. It seems that implicit cast from integer to boolean is allowed... under all circumstances... depending on what specification the compiler is following :D

For future references, I'll just summarize this as "C and C++ are minefields". We'll just add that to the list of WTF behaviors.

By the way, if you think that "C has had bool for 19 years" [the C99 spec specifically]. You clearly didn't work in C for long enough with a large variety of tools. The world is bigger than just GCC.

Re:Let’s Stop Bashing C by mining on Friday December 02, 2016 @08:34PM (#13093712)
> But it doesn't give one when the cast is in a loop condition. That is weird.

I believe that the justification for that is that you'll often want to do e.g.

    while (node) {
      node.val += 3;
      node = node->next;
    }
Implicit conversion of a type into a bool is pretty useful here, or for e.g.

    while (std::cin >> x >> y) { ... }
Re:Let’s Stop Bashing C by dbaupp on Friday December 02, 2016 @06:45PM (#13093275)
I imagine the warning is following the rules for explicit constructors/operators in C++: an if condition is considered an "explicit" call to an `operator bool`. http://en.cppreference.com/w/cpp/language/explicit