GCC version: 3.2.3 Host: Linux Sample code. #include <netinet/in.h> int main() { unsigned short t; ::htons(t); return 0; } /usr/bin/g++ -O2 t.cpp t.cpp: In function `int main()': t.cpp:10: syntax error before `__extension__' t.cpp:10: `__x' undeclared (first use this function) t.cpp:10: (Each undeclared identifier is reported only once for each function it appears in.) t.cpp:10: `__v' undeclared (first use this function) t.cpp: At global scope: t.cpp:10: syntax error before `)' token If I don't use -O2 the code compiles. If I change ::htons to htons the code compiles even with -O2. Why does it fail for ::htons()
htons is a macro, use parens or #undef to suppress it.