Don’t call your global variable ‘socket’
Posted on December 16, 2009
This small C++ issue ate my day yesterday. If you call your global variable 'socket' the compiler will use it for the socket-syscall (even when called by ::socket).
Ok, who would do that? In the same file you get the error:
main.cpp:5: error: ‘int socket’ redeclared as different kind of symbol
/usr/include/sys/socket.h:105: error: previous declaration of ‘int socket(int, int, int)’
But when done in a seperate file you will just get a SIGSEGV error at the call to socket (..) without a chance finding out whats the trouble. Especially when you don't use the socket function directly, e.g. it's hidden by boost::asio.