public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53760] New: attribute packed doesn't pack inner structs
@ 2012-06-24 14:19 stsp at users dot sourceforge.net
  2012-06-24 17:59 ` [Bug c/53760] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: stsp at users dot sourceforge.net @ 2012-06-24 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53760
           Summary: attribute packed doesn't pack inner structs
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: stsp@users.sourceforge.net


The following code:

---
#include <stdio.h>

struct A {
    char a:1;
    struct {
        char a:1;
    } __attribute__((packed)) s1;
    struct {
        char a:1;
    } __attribute__((packed)) s2;
    struct {
        char a:1;
    } __attribute__((packed)) s3;
} __attribute__((packed));

int main()
{
    printf("%lu\n", sizeof(struct A));
    return 0;
}
---

prints '4' instead of '1'.
Every bitfield seems to be occupying an entire byte.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
@ 2012-06-24 17:59 ` pinskia at gcc dot gnu.org
  2012-06-24 18:09 ` stsp at users dot sourceforge.net
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-06-24 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-06-24 17:59:08 UTC ---
I think having a size of 4 is correct.  Packed is on a byte boundary and not a
bit boundary.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
  2012-06-24 17:59 ` [Bug c/53760] " pinskia at gcc dot gnu.org
@ 2012-06-24 18:09 ` stsp at users dot sourceforge.net
  2012-06-24 18:13 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: stsp at users dot sourceforge.net @ 2012-06-24 18:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Stas Sergeev <stsp at users dot sourceforge.net> 2012-06-24 18:09:18 UTC ---
Even if "attribute packed" have nothing to do with this,
then why doesn't it pack regardless?
Eg,
struct {
char a:1;
char b:1;
char c:1;
}
would be packed, no matter what.
Why does the same not happen to the struct?
Any way to force such a packing? There is an
obvious (IMHO) need for that.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
  2012-06-24 17:59 ` [Bug c/53760] " pinskia at gcc dot gnu.org
  2012-06-24 18:09 ` stsp at users dot sourceforge.net
@ 2012-06-24 18:13 ` pinskia at gcc dot gnu.org
  2012-06-24 18:20 ` stsp at users dot sourceforge.net
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-06-24 18:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-06-24 18:12:39 UTC ---
Because each inner struct has to be at a byte boundary.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
                   ` (2 preceding siblings ...)
  2012-06-24 18:13 ` pinskia at gcc dot gnu.org
@ 2012-06-24 18:20 ` stsp at users dot sourceforge.net
  2012-06-25  6:52 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: stsp at users dot sourceforge.net @ 2012-06-24 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Stas Sergeev <stsp at users dot sourceforge.net> 2012-06-24 18:20:00 UTC ---
Is this mandated in some spec or doc?
Any way to defeat that? :)
Btw, why can't the "attribute packed" be
allowed to pack on a bit boundary too?
Sounds like a useless limitation, no?


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
                   ` (3 preceding siblings ...)
  2012-06-24 18:20 ` stsp at users dot sourceforge.net
@ 2012-06-25  6:52 ` jakub at gcc dot gnu.org
  2012-06-25  8:12 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-06-25  6:52 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-06-25 06:51:12 UTC ---
It is not a useless limitation.  While you can't take address of a bitfield,
you can take address of a struct field, even when it contains only bitfields.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
                   ` (4 preceding siblings ...)
  2012-06-25  6:52 ` jakub at gcc dot gnu.org
@ 2012-06-25  8:12 ` rguenth at gcc dot gnu.org
  2012-06-25 10:07 ` ebotcazou at gcc dot gnu.org
  2012-06-25 10:30 ` stsp at users dot sourceforge.net
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-06-25  8:12 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-06-25 08:11:17 UTC ---
Indeed.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
                   ` (5 preceding siblings ...)
  2012-06-25  8:12 ` rguenth at gcc dot gnu.org
@ 2012-06-25 10:07 ` ebotcazou at gcc dot gnu.org
  2012-06-25 10:30 ` stsp at users dot sourceforge.net
  7 siblings, 0 replies; 9+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2012-06-25 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot
                   |                            |gnu.org

--- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2012-06-25 10:06:23 UTC ---
> Is this mandated in some spec or doc?
> Any way to defeat that? :)

If you're ready to switch language.  The Ada language supports bit-packedness.


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

* [Bug c/53760] attribute packed doesn't pack inner structs
  2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
                   ` (6 preceding siblings ...)
  2012-06-25 10:07 ` ebotcazou at gcc dot gnu.org
@ 2012-06-25 10:30 ` stsp at users dot sourceforge.net
  7 siblings, 0 replies; 9+ messages in thread
From: stsp at users dot sourceforge.net @ 2012-06-25 10:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Stas Sergeev <stsp at users dot sourceforge.net> 2012-06-25 10:29:40 UTC ---
I think gcc C could support it too by
some "pack_harder" attribute (and then not
allow pointers to such structs), but I've got
the point. :)


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

end of thread, other threads:[~2012-06-25 10:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-24 14:19 [Bug c/53760] New: attribute packed doesn't pack inner structs stsp at users dot sourceforge.net
2012-06-24 17:59 ` [Bug c/53760] " pinskia at gcc dot gnu.org
2012-06-24 18:09 ` stsp at users dot sourceforge.net
2012-06-24 18:13 ` pinskia at gcc dot gnu.org
2012-06-24 18:20 ` stsp at users dot sourceforge.net
2012-06-25  6:52 ` jakub at gcc dot gnu.org
2012-06-25  8:12 ` rguenth at gcc dot gnu.org
2012-06-25 10:07 ` ebotcazou at gcc dot gnu.org
2012-06-25 10:30 ` stsp at users dot sourceforge.net

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