Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Sep 2004 13:24:15 -0700
From:      Pavlin Radoslavov <pavlin@icir.org>
To:        freebsd-current@freebsd.org
Cc:        pavlin@icir.org
Subject:   g++ may fail to compile __packed structures
Message-ID:  <200409062024.i86KOFwK070699@possum.icir.org>

next in thread | raw e-mail | index | archive | help
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 <stdio.h>
#include <stdlib.h>
#include <string.h>

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<int&>(f1.f));
    copy_out(f1.f);

    exit(0);
}



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