__extension__({}) as used in FreeBSD3.1 htonl macro vs. C++ initializer

Drew Eckhardt drew@plutotech.com
Tue Apr 13 19:13:00 GMT 1999


Under i86 FreeBSD 3.1-stable, using these  versions of g++

    gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
    gcc version 2.7.2.1

the BSD htonl macro which uses __extension__({}) can't be used in C++ 
constructor initializer lists.


The test program

    #include <sys/param.h>
    struct foo {
	foo (long x) : bar(htonl(x)) { }
	long bar;
    };


Expands to something like

    typedef unsigned long u_long;
    struct foo {
	foo (long x) : bar(__extension__ ({ register u_long __X = ( x ); __asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" : "=q" (__X) : "0" (__X)); __X; }) ) { }
	long bar;
    };

and produces these errors

    htonl.cc:4: parse error before `)'
    htonl.cc:4: missing ';' before right brace
    htonl.cc:5: semicolon missing after declaration of `foo'
    htonl.cc: In method `foo::foo(long int)':
    htonl.cc:4: parse error at end of saved text

-- 
Work: <drew@plutotech.com>   | For those who don't, no explanation is possible.
Play: <drew@poohsticks.org>  | For those who do, no explanation is necessary.  
Home page: http://www.poohsticks.org/drew/ ">Home Page</a>


More information about the Gcc-bugs mailing list