From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4A595F8D.1080408@tecmav.com> Date: Sun, 12 Jul 2009 05:59:09 +0200 From: Adriano Verardo User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20080213 MIME-Version: 1.0 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [9fans] C compiler question Topicbox-Message-UUID: 1be5c556-ead5-11e9-9d60-3106f5b1d025 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 { // sizeof = 100 struct NeverDefined nf; // Unknown, definition not #included } S1 struct { // 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