Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Sep 2004 08:25:42 -0400
From:      Craig Rodrigues <rodrigc@crodrigues.org>
To:        Pavlin Radoslavov <pavlin@icir.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: g++ may fail to compile __packed structures
Message-ID:  <20040907122542.GA17809@crodrigues.org>
In-Reply-To: <200409062024.i86KOFwK070699@possum.icir.org>
References:  <200409062024.i86KOFwK070699@possum.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 06, 2004 at 01:24:15PM -0700, Pavlin Radoslavov wrote:
> It appears that the lastest g++ compiler that comes with FreeBSD may
> fail to compile a __packed structure when one of its fields is
> passed by reference. At the end of this email is a sample program
> that demonstrates the problem. The compilation error is:
> 
> pavlin@carp[14] g++34 test.cc
> test.cc: In function `int main()':
> test.cc:22: error: cannot bind packed field `f1.foo::f' to `int&'
> Exit 1
> 
> The problem appears to exist only with the recent g++ compiler that
> comes with FreeBSD:

This change was made recently to gcc:
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01664.html

Apparently in C++, you are not allowed to  have non-const references
to packed fields.  See:
http://www.comnets.rwth-aachen.de/doc/c++std/decl.html#dcl.init.ref


Your testcase will compile if you change your copy_out function to:

void
copy_out(const int& i)
{
//    i = 0x11223344;
}


but your testcase will not be too useful.

You might want to follow up on one of the GCC mailing lists.

-- 
Craig Rodrigues        
http://crodrigues.org
rodrigc@crodrigues.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040907122542.GA17809>