From owner-freebsd-current@FreeBSD.ORG Mon Sep 6 20:24:15 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 466B116A4CE for ; Mon, 6 Sep 2004 20:24:15 +0000 (GMT) Received: from possum.icir.org (possum.icir.org [192.150.187.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1D90B43D48 for ; Mon, 6 Sep 2004 20:24:15 +0000 (GMT) (envelope-from pavlin@icir.org) Received: from possum.icir.org (localhost [127.0.0.1]) by possum.icir.org (8.12.9p1/8.12.8) with ESMTP id i86KOFwK070699; Mon, 6 Sep 2004 13:24:15 -0700 (PDT) (envelope-from pavlin@possum.icir.org) Message-Id: <200409062024.i86KOFwK070699@possum.icir.org> To: freebsd-current@freebsd.org Date: Mon, 06 Sep 2004 13:24:15 -0700 From: Pavlin Radoslavov X-Mailman-Approved-At: Tue, 07 Sep 2004 11:41:37 +0000 cc: pavlin@icir.org Subject: 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: Mon, 06 Sep 2004 20:24:15 -0000 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: pavlin@carp[15] g++34 --version g++34 (GCC) 3.4.2 20040806 (prerelease) [FreeBSD] E.g., the problem doesn't exist with older compilers like 3.3.x from FreeBSD or the vanilla g++-3.4.1 from http://gcc.gnu.org/. It is not even in 3.4.0 from FreeBSD: ("g++34 (GCC) 3.4.0 20040310 (prerelease) [FreeBSD]") Thanks, Pavlin #include #include #include struct foo { int f; } __packed; void copy_out(int& i) { i = 0x11223344; } int main() { struct foo f1; memset(&f1, 0, sizeof(f1)); // copy_out(reinterpret_cast(f1.f)); copy_out(f1.f); exit(0); }