error: Unsupported feature: Gnu statement expressions in C++

error: Unsupported feature: Gnu statement expressions in C++

I received the above error message when trying to compile

server.sin_port = htons(usPort);

It is complaining about htons. Can you explain what this error really means? Does it mean that this macro isn't supported in C++ or does it mean that I have a library compatibility problem?

Thank you

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

htons, ntohs, htonl, and ntohl on Linux platforms are implemented as a "statement expression", which is a gcc extension.

In order to use these in icc, put the following after the in.h #include:

#if defined(__ICC)
// icc doesn't like GNU __extension__ functions
// this has to happen AFTER !!
#undef htons
#undef ntohs
#undef htonl
#undef ntohl
#define htons(x) __bswap_constant_16(x)
#define ntohs(x) __bswap_constant_16(x)
#define htonl(x) __bswap_constant_32(x)
#define ntohl(x) __bswap_constant_32(x)
#endif // defined(_ICC)

Hope this helps!

Regards,
-scott

Yes, thank you that worked. And especially thank you for explaining that a "statement expression" is a GCC extension.

I actually just fixed that same error in our code yesterday, so it was a simple matter of timing. ;-)

By the way these are targeted for fixes in a future version of the compiler. Meanwhile we have to use the workarounds

I think that one might be better to avoid statement expressions in C++. The feature is described in the gcc online doc:
http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Statement-Exprs.html

A careful reader would note the following:

"Statement expressions are not supported fully in G++, and their fate there is unclear. (It is possible that they will become fully supported at some point, or that they will be deprecated, or that the bugs that are present will continue to exist indefinitely.) Presently, statement expressions do not work well as default arguments."

So, in the words of Dirty Harry "... you've got to ask yourself one question: Do I feel lucky?"

-Jeff

Leave a Comment

Please sign in to add a comment. Not a member? Join today