public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mcvick_e at iname dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/28763] sizeof macro appears broken when bitfields are in structures Date: Thu, 17 Aug 2006 22:18:00 -0000 [thread overview] Message-ID: <20060817221755.378.qmail@sourceware.org> (raw) In-Reply-To: <bug-28763-8046@http.gcc.gnu.org/bugzilla/> ------- Comment #3 from mcvick_e at iname dot com 2006-08-17 22:17 ------- Are you telling me that if I put two of those structures side by side in memory that GNU will mis-align them even though I pass the flag -mstrict-align? That couldn't possibly be since the align flag states to use strict type alignment. The GNU documentation also states that it will align to the smallest base type of the bitfield. Thus an 8-bit bitfield has 8-bit alignment, a 16-bit has 16-bit alignment, and a 32-bit has 32-bit alignment. In the example I have shown, it clearly shows that a 32-bit bitfield is defaulting to byte alignment as far as size allocation is concerned. I've ran objdump on the file, and even though the size is reported as smaller, it ALLOCATES all 32-bits for alignment reasons. According to the C-Speficiation (which applies to C++ as well) ... The size of an object of a structure type is the amount of storage necessary to represent all components of that type, including any unused padding space between or after the components. The rule is that the structure will be padded out to the size the type would occupy as an element of array of such types. So if you had an array of foo1's and an array of foo2's you would see exactly the same alignment in memory. Just that sizeof reports something incorrect. Thus if you were wanting to walk the array by say a byte pointer, and then went to increment that byte pointer by the sizeof the structure, in one case you would get correct behavior, and in the other you would get undefined or incorrect behavior. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28763
next prev parent reply other threads:[~2006-08-17 22:18 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-08-17 17:44 [Bug c++/28763] New: " mcvick_e at iname dot com 2006-08-17 18:02 ` [Bug c++/28763] " pinskia at gcc dot gnu dot org 2006-08-17 18:04 ` [Bug target/28763] " pinskia at gcc dot gnu dot org 2006-08-17 22:18 ` mcvick_e at iname dot com [this message] 2006-08-17 22:20 ` pinskia at gcc dot gnu dot org 2006-08-17 22:28 ` mcvick_e at iname dot com 2006-08-17 22:35 ` mcvick_e at iname dot com 2006-08-18 0:03 ` mcvick_e at iname dot com 2006-08-22 16:42 ` mcvick_e at iname dot com 2009-06-16 16:25 ` [Bug target/28763] wrong size of struct with some bit-fields on ppc-eabi mcvick_e at iname dot com 2009-06-16 16:27 ` pinskia at gcc dot gnu dot org 2009-06-16 16:30 ` mcvick_e at iname dot com 2009-06-16 16:31 ` pinskia at gcc dot gnu dot org 2009-06-16 16:55 ` mcvick_e at iname dot com 2009-06-16 17:27 ` [Bug target/28763] sizeof() and __attribute__ broken with " joseph at codesourcery dot com 2009-06-16 17:43 ` mcvick_e at iname dot com 2009-06-16 20:03 ` joseph at codesourcery dot com
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=20060817221755.378.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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: linkBe 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).