public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/33823]  New: bitfields on packed struct aligns by a few bits if the types differ
@ 2007-10-20  1:47 alexandre dot nunes at gmail dot com
  2007-10-20  1:49 ` [Bug c/33823] " alexandre dot nunes at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: alexandre dot nunes at gmail dot com @ 2007-10-20  1:47 UTC (permalink / raw)
  To: gcc-bugs

I have two structs (the unions are there for the sake of testing, it still
behaves the same without them):

#define ATTRIBUTE_PACKED_STRUCT __attribute__((gcc_struct,packed))
#include <stdio.h>
#include <stdint.h>

typedef union  ATTRIBUTE_PACKED_STRUCT
{
  struct ATTRIBUTE_PACKED_STRUCT {
    uint8_t a:1,
            b:7,
            c:7;
    uint16_t d:16;
    uint8_t e:7;
    uint8_t f:7;
    uint16_t g:10;
    uint16_t h:10;
    uint16_t i:12;
    uint8_t  j:7;
    uint8_t k:8;
    uint16_t l:15;
  };
  unsigned char values[14];
} test_struct;

typedef union  ATTRIBUTE_PACKED_STRUCT
{
  struct ATTRIBUTE_PACKED_STRUCT {
    uint32_t a:1,
            b:7,
            c:7;
    uint32_t d:16;
    uint32_t e:7;
    uint32_t f:7;
    uint32_t g:10;
    uint32_t h:10;
    uint32_t i:12;
    uint32_t  j:7;
    uint32_t k:8;
    uint32_t l:15;
  };
  unsigned char values[14];
} test_struct2;

These structs have the same effective size, i.e., removing them from the
unions, and having sizeof() applied to them yelds the 14 bytes size, but the
members dispostion differs, i.e. the 'e' member is a bit ahead in the first
struct (test_struct) than in the second. 

I didn't expect the type change to force an alignment. It that's standard
behaviour, then I would like to propose a documentation request; The ms_struct
alignment is described quite well on gcc's page, but gcc's default one isn't.

If that's not expected behaviour, then what would be? In case it is, could
someone please point me to a documentation source, i.e. an ISO C pointer or
whatever reasoning is behind this, if any?

Thanks.


-- 
           Summary: bitfields on packed struct aligns by a few bits if the
                    types differ
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexandre dot nunes at gmail dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33823


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-02-14 23:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-20  1:47 [Bug c/33823] New: bitfields on packed struct aligns by a few bits if the types differ alexandre dot nunes at gmail dot com
2007-10-20  1:49 ` [Bug c/33823] " alexandre dot nunes at gmail dot com
2007-10-20  9:47 ` rguenth at gcc dot gnu dot org
2007-10-20 12:20 ` alexandre dot nunes at gmail dot com
2007-10-20 12:55 ` alexandre dot nunes at gmail dot com
2007-10-20 13:35 ` alexandre dot nunes at gmail dot com
2007-11-02 16:58 ` alexandre dot nunes at gmail dot com
2008-02-14 21:34 ` rguenth at gcc dot gnu dot org
2008-02-14 22:07 ` alexandre dot nunes at gmail dot com
2008-02-14 23:05 ` rguenth at gcc dot gnu dot org
2008-02-14 23:16 ` alexandre dot nunes at gmail dot com

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).