From owner-freebsd-current@FreeBSD.ORG Tue Sep 7 12:25:42 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 51CAE16A4CE for ; Tue, 7 Sep 2004 12:25:42 +0000 (GMT) Received: from rwcrmhc11.comcast.net (rwcrmhc11.comcast.net [204.127.198.35]) by mx1.FreeBSD.org (Postfix) with ESMTP id 28AB143D1D for ; Tue, 7 Sep 2004 12:25:42 +0000 (GMT) (envelope-from rodrigc@crodrigues.org) Received: from h00609772adf0.ne.client2.attbi.com ([66.30.114.143]) by comcast.net (rwcrmhc11) with ESMTP id <2004090712254101300aqiame>; Tue, 7 Sep 2004 12:25:41 +0000 Received: from h00609772adf0.ne.client2.attbi.com (localhost [127.0.0.1]) i87CPgus017860; Tue, 7 Sep 2004 08:25:43 -0400 (EDT) (envelope-from rodrigc@h00609772adf0.ne.client2.attbi.com) Received: (from rodrigc@localhost)i87CPgTO017859; Tue, 7 Sep 2004 08:25:42 -0400 (EDT) (envelope-from rodrigc) Date: Tue, 7 Sep 2004 08:25:42 -0400 From: Craig Rodrigues To: Pavlin Radoslavov Message-ID: <20040907122542.GA17809@crodrigues.org> References: <200409062024.i86KOFwK070699@possum.icir.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200409062024.i86KOFwK070699@possum.icir.org> User-Agent: Mutt/1.4.1i cc: freebsd-current@freebsd.org Subject: Re: g++ may fail to compile __packed structures X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2004 12:25:42 -0000 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