🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6289

g++ 2.7.1 and 2.7.2 __attribute__ ((packed)) fails

#6289
From: Russell Senior
Date: Sun, 10 Dec 1995 00:00
50 lines
1893 bytes
I recently observed an unexpected behavior with g++, which I have
traced back to the transition between 2.7.0 and 2.7.1.  I have
observed the faulty behavior on both i586 Linux ELF 1.3.43 and 
IRIX 5.3 SGI.

The problem:  ``__attribute__ ((packed))'' works in gcc, but not in
g++.  Observe the following test case, test.c:

#include <stddef.h>
#include <stdio.h>

struct test {
  char a __attribute__ ((packed));
  long b __attribute__ ((packed));
} c;

main()
{
  printf("sizeof(struct test) = %u\n",sizeof(struct test));
  printf("offsetof(struct test,a) = %u\n",offsetof(struct test,a));
  printf("offsetof(struct test,b) = %u\n",offsetof(struct test,b));
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With the C compiler, gcc, I get the expected results:

russell@tdb[/tmp] $ gcc test.c
russell@tdb[/tmp] $ a.out
sizeof(struct test) = 5
offsetof(struct test,a) = 0
offsetof(struct test,b) = 1

However, compiling the exact same source file with the C++ compiler,
g++, I get unexpected results:

russell@tdb[/tmp] $ g++ test.c
russell@tdb[/tmp] $ a.out
sizeof(struct test) = 8
offsetof(struct test,a) = 0
offsetof(struct test,b) = 4

Thanks!

-- 
Russell S. Senior                                  russell@tdb.com
T. Dan Bracken, Inc.                          seniorr@teleport.com
5415 S.E. Milwaukie Avenue, Suite 4                 (503) 233-2181
Portland, Oregon  97202
Technical Details
Message-ID: <199512110318.TAA04156@desiree.teleport.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,2f1599c5d918884,start
X-Google-Attributes: gid113d02,public
From: seniorr@teleport.com (Russell Senior)
Subject: g++ 2.7.1 and 2.7.2 __attribute__ ((packed)) fails
Date: 1995/12/10
Message-ID: <199512110318.TAA04156@desiree.teleport.com>
X-Deja-AN: 121483975
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: GNUs Not Usenet
newsgroups: gnu.gcc.bug