Article View: gnu.gcc.bug
Article #6325structure size
From: Travis Bauer
Date: Tue, 19 Dec 1995 00:00
Date: Tue, 19 Dec 1995 00:00
68 lines
2614 bytes
2614 bytes
I cannot decide whether the following is a bug or a feature :)
Consider the following code:
#include"stdio.h"
struct Toilday {
char header[6];
long date;
char wname[16];
};
main()
{
Toilday oilday;
printf("oilday: %d\n\n", sizeof(oilday));
printf("oilday.header: %d\n", sizeof(oilday.header));
printf("oilday.date: %d\n", sizeof(oilday.date));
printf("oilday.wname: %d\n", sizeof(oilday.wname));
}
It produces the following output:
oilday: 28
oilday.header: 6
oilday.date: 4
oilday.wname: 16
Now if my arithmetic is up to speed, I think the total size of the
structure should be 26. But is weighs in at 28. I did some
debugging and found the extra two bytes between the header and date fields.
Adding more fields of different types adds more unaccounted for
bytes. In the original data structure I need for the program I'm
writing, I found 17 extra bytes. I couldn't find a pattern to the
addition of bytes, but they seem to occur mostly between
fields of different types.
The reason I discovered this is that I am writing code that needs to
be able to write data into oilday as a void pointer. In Borland's
Turbo C++, the structures had no extra bytes so I could calculate the
field positions in the variable as offsets from the base address of
oilday. But with the extra bytes in the structure, the calculation
does not hold true.
I am using Linux 1.2.1, slackware release 2.2.0. My version of the
GCC compiler is 2.6.3. I used the command g++ to compile the code,
and used the filename test.C. I used no command line options for the
compile. GCC was automatically installed by the slackware setup
program.
Incidently, the GCC manual where I got this address indicates that
BUG-GCC and HELP-GCC are mailing lists. Am I allowed to join these
lists? If so, what is the administrative address? They weren't
listed in the GCC manual.
Thank you,
-----------------------------------------------
Travis Bauer
http://acc.jc.edu/~bauer
We don't understand the software,
and we don't always understand the hardware,
but we can see the blinking lights!
-----------------------------------------------
Technical Details
Message-ID:
<m0tS2ZY-0003gjC@acc.jc.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,23ed274e9f2aff0b X-Google-Attributes: gid113d02,public From: bauer@acc.jc.edu (Travis Bauer) Subject: structure size Date: 1995/12/19 Message-ID: <m0tS2ZY-0003gjC@acc.jc.edu> X-Deja-AN: 122307805 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug