Bug 33793 - global scoping for htons/htohs fails (::htons)
Summary: global scoping for htons/htohs fails (::htons)
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-16 15:39 UTC by amit
Modified: 2007-10-16 15:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description amit 2007-10-16 15:39:19 UTC
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()
Comment 1 Andreas Schwab 2007-10-16 15:46:44 UTC
htons is a macro, use parens or #undef to suppress it.