9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] C compiler question
@ 2009-07-12  3:59 Adriano Verardo
  2009-07-12 16:59 ` erik quanstrom
  0 siblings, 1 reply; 18+ messages in thread
From: Adriano Verardo @ 2009-07-12  3:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hi, all.

Yesterday I observed different sizeof() of a union in a library function
and in the main program. The reason seems to be a forgotten #include
in a library source.

union U
{
    struct
    {
          <fields of defined types>            //  sizeof = 100
          struct NeverDefined  nf;              //  Unknown, definition
not #included
    } S1

    struct
    {
          <fields of defined types>            //  sizeof = 20
    } S2
};

8c silently accept the above definition and sizeof(U) is 100.  ???
The sources which include the definition of "NeverDefined" are
regularly compiled too and sizeof(U) = 100 + sizeof(NeverDefined).

This happens only if the undefined field is the last of the structure.
If it is followed by other (defined or not defined) field(s), the compiler
correctly detects the error.

Is this behaviour correct ?

Thanks in advance.

a.verardo







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

end of thread, other threads:[~2009-07-15 11:38 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-12  3:59 [9fans] C compiler question Adriano Verardo
2009-07-12 16:59 ` erik quanstrom
2009-07-14  2:58   ` Adriano Verardo
2009-07-14  3:14     ` erik quanstrom
2009-07-14 14:00       ` Adriano Verardo
2009-07-14 14:57         ` erik quanstrom
2009-07-14 16:26           ` Adriano Verardo
2009-07-14 16:38             ` erik quanstrom
2009-07-14 17:18       ` Roman V Shaposhnik
2009-07-14 17:46         ` erik quanstrom
2009-07-14 18:59           ` Roman V Shaposhnik
2009-07-14 19:29             ` erik quanstrom
2009-07-14 19:45               ` Russ Cox
2009-07-15 11:34                 ` Ethan Grammatikidis
2009-07-15 11:38                   ` erik quanstrom
2009-07-14 20:28               ` [9fans] pointers to incomplete types Roman V Shaposhnik
2009-07-15  9:25               ` [9fans] C compiler question robert wilson
2009-07-14  4:00     ` Russ Cox

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 NNTP newsgroup(s).