public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays
@ 2012-09-02  1:36 mikulas at artax dot karlin.mff.cuni.cz
  2012-09-02  1:53 ` [Bug c/54454] " mikulas at artax dot karlin.mff.cuni.cz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mikulas at artax dot karlin.mff.cuni.cz @ 2012-09-02  1:36 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54454
           Summary: gcc violates c99 specification w.r.t. flexible arrays
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mikulas@artax.karlin.mff.cuni.cz
              Host: hppa-linux-gnu
            Target: hppa-linux-gnu
             Build: hppa-linux-gnu


The c99 specification says (section 6.7.2.1, paragraph 16): "The size of the
structure [with flexible array member] shall be equal to the offset of the
last element of an otherwise identical structure that replaces the flexible
array member with an array of unspecified length". This is not true in gcc.
Try to complile and run this program: the size of the structure with the
flexible array member is 8. However, offset of the flexible array member is 6.
According to the specification, sizeof(struct flexible) should be 6.

#include <stdio.h>
#include <stddef.h>

struct flexible {
        unsigned a;
        unsigned short b;
        unsigned char array[];
};

struct not_flexible {
        unsigned a;
        unsigned short b;
        unsigned char array[1];
};

int main(void)
{
        printf("sizeof(struct flexible) = %d\n", (int)sizeof(struct flexible));
        printf("offsetof(struct not_flexible, array)) = %d\n",
(int)offsetof(struct not_flexible, array));
        printf("offsetof(struct flexible, array)) = %d\n", (int)offsetof(struct
flexible, array));
        return 0;
}


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

end of thread, other threads:[~2024-03-14 20:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-02  1:36 [Bug c/54454] New: gcc violates c99 specification w.r.t. flexible arrays mikulas at artax dot karlin.mff.cuni.cz
2012-09-02  1:53 ` [Bug c/54454] " mikulas at artax dot karlin.mff.cuni.cz
2012-09-02  2:06 ` pinskia at gcc dot gnu.org
2012-09-02 12:20 ` jsm28 at gcc dot gnu.org
2024-03-14 20:20 ` pinskia at gcc dot gnu.org

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