I encountered a Socket operation on non-socket error in some of my network code when I called connect and spent a lot of time trying to figure out what was causing it. Finally, I realized that the following line of code is causing the problem:
if ((sockfd = socket( ai->ai_family, ai->ai_socktype, ai->ai_protocol) < 0)) {
See the problem? This is what the line looks like:
if ((sockfd = socket( ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0) {
I do not understand why the first incorrect line does not cause a warning. In other words, there should not be a general view:
if ( foo = bar() < baz ) do_something();
Looks weird for the compiler, especially works with g++ -Wall -Wextra ?
If not, should it at least show up as a "bad style" for cppcheck, which I also run as part of my compilation?
source share