From: Sam Lantinga <slouken@devolution.com>
To: gcc@gcc.gnu.org
Cc: slouken@devolution.com
Subject: C++ bug in structure packing and inheritance
Date: Sat, 15 Dec 2001 15:07:00 -0000 [thread overview]
Message-ID: <E16FNqC-0007Qg-00@twomix.devolution.com> (raw)
There seems to be a bug in structure packing in that if you have
two classes or structures that both inherit from a class with no
data members, then they will be the wrong size.
A simple example follows:
#include <stddef.h>
#include <stdio.h>
struct a {
};
struct b : public a {
float x;
float y;
};
struct c : public a {
b data;
float z;
};
main()
{
printf("size of a = %d (should be 0)\n", sizeof(a));
printf("size of b = %d (should be 8)\n", sizeof(b));
printf("size of c = %d (should be 12)\n", sizeof(c));
printf("offset of c.z = %d (should be 8)\n", offsetof(c,z));
}
Sample output with the current CVS of gcc is:
size of a = 1 (should be 0)
size of b = 8 (should be 8)
size of c = 16 (should be 12)
offset of c.z = 12 (should be 8)
If this is correct, I would appreciate it if somebody could explain it.
Thanks,
-Sam Lantinga, Software Engineer, Blizzard Entertainment
next reply other threads:[~2001-12-15 23:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-15 15:07 Sam Lantinga [this message]
2001-12-15 16:09 ` Daniel Berlin
2001-12-15 23:40 Sam Lantinga
2001-12-15 23:57 ` Alexandre Oliva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E16FNqC-0007Qg-00@twomix.devolution.com \
--to=slouken@devolution.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).