Re: g++ may fail to compile __packed structures

From: Pavlin Radoslavov <pavlin_at_icir.org>
Date: Tue, 07 Sep 2004 13:32:31 -0700
> 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_at_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_at_crodrigues.org
Received on Tue Sep 07 2004 - 18:32:33 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:11 UTC