Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 07 Sep 2004 13:32:31 -0700
From:      Pavlin Radoslavov <pavlin@icir.org>
To:        Craig Rodrigues <rodrigc@crodrigues.org>
Cc:        Pavlin Radoslavov <pavlin@icir.org>
Subject:   Re: g++ may fail to compile __packed structures 
Message-ID:  <200409072032.i87KWVwK035940@possum.icir.org>
In-Reply-To: Message from Craig Rodrigues <rodrigc@crodrigues.org>  <20040907122542.GA17809@crodrigues.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

Yes, I am aware of that patch (when I did some search on the subject
before posting my email). However, again, when I use the vanilla g++
3.4.1 which is 2 months old, or even the vanilla 3.4.2 which was
just released today, I don't get the compilation error.
Hence, why the disparity between the vanilla gcc and the lastest
gcc that comes with FreeBSD?

> 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

The above URL doesn't say anything about packed fields.
Please correct me if I am wrong, but I think that __packed is not
part of the C or C++ standart, hence this leaves some gray area for
interpretation. Anyway, this is a subject for the gcc ML...

However, I am trying to find-out why the FreeBSD gcc behaves
different from the vanilla gcc, and which compiler has the "right"
behavior.

Thanks,
Pavlin

> 
> 
> 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?200409072032.i87KWVwK035940>