[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread pinskia at gcc dot gnu dot org


--- Comment #1 from pinskia at gcc dot gnu dot org  2008-08-13 21:26 ---
  struct X { uint32_t a:17; uint8_t b:8; bool c:1; };
0...16 is a as uint32_t is more than 17 bytes
17...24 is b as uint8_t is 8 bytes
25...26 is c as bool is 1 byte

so 26bits which is a little over 4 bytes. so it needs to be rounded (aligned)
to 4 byte so we get 8 bytes.

I don't see what the issue here is.  if we replace uint32_t with uint16_t, the
sizes are reduced as it only stores 16 bytes and the alignment of the struct
becomes 2 byte aligned.

Why do you think the original struct should be 4 bytes?  I cannot count how it
could ever be 4 bytes really except for replacing of uint32_t with uint16_t.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread gcc-bugzilla at contacts dot eelis dot net


--- Comment #2 from gcc-bugzilla at contacts dot eelis dot net  2008-08-13 
21:39 ---
(In reply to comment #1)
 so 26bits which is a little over 4 bytes.

I don't follow. 4 bytes is 4*8=32 bits, which is more than 26, no?


-- 


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread pinskia at gcc dot gnu dot org


--- Comment #3 from pinskia at gcc dot gnu dot org  2008-08-13 21:43 ---
I don't follow. 4 bytes is 4*8=32 bits, which is more than 26, no?

Or the ABI says the different types are not merged together.  Really you have
to look into what the ABI says to figure out the correct answer.  I don't have
the x86_64 ABI in front of me right now.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

   GCC host triplet|x86_64-pc-linux |
 GCC target triplet||x86_64-pc-linux-gnu


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread rguenth at gcc dot gnu dot org


--- Comment #4 from rguenth at gcc dot gnu dot org  2008-08-13 21:59 ---
Seems like we do that since forever, so we cannot change this anyway.  But
surely it looks unintuitive that

struct X { uint32_t a:17; uint16_t b:8; uint8_t c:1; };

is 4 bytes while

struct X { uint32_t a:17; uint8_t b:8; uint8_t c:1; };

is 8 bytes in size.


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 CC||rguenth at gcc dot gnu dot
   ||org, matz at gcc dot gnu dot
   ||org
   GCC host triplet||x86_64-pc-linux
 GCC target triplet|x86_64-pc-linux-gnu |


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread rguenth at gcc dot gnu dot org


--- Comment #5 from rguenth at gcc dot gnu dot org  2008-08-13 22:01 ---
This is also 4 bytes in size:

struct X { uint32_t a:17; uint16_t b:8; uint16_t c:1; };


-- 


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread rguenth at gcc dot gnu dot org


--- Comment #6 from rguenth at gcc dot gnu dot org  2008-08-13 22:05 ---
struct X { uint32_t a:17; uint8_t b:8; uint8_t c:1; } __attribute__((packed));

brings it down to 5 bytes  (we seem to never pack chars with other types)


-- 


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread pinskia at gcc dot gnu dot org


--- Comment #7 from pinskia at gcc dot gnu dot org  2008-08-13 22:16 ---
brings it down to 5 bytes  (we seem to never pack chars with other types)

We do, but we don't packed if it overflows into the next unit.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|WAITING |UNCONFIRMED


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread rguenth at gcc dot gnu dot org


--- Comment #8 from rguenth at gcc dot gnu dot org  2008-08-13 22:20 ---
The relevant ABI says
 a bit-field mut entirely reside in a storage unit appropriate for
  its declared type

which means it all makes very much sense.


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


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



[Bug c++/37119] sizeof simple struct consisting of bit-fields too large and unpredictable

2008-08-13 Thread gcc-bugzilla at contacts dot eelis dot net


--- Comment #9 from gcc-bugzilla at contacts dot eelis dot net  2008-08-13 
22:24 ---
Ok, I see. Sorry for wasting your time.


-- 


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