Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com X-Originating-IP: [24.234.209.180] From: "Jim Buckeyne" To: cygwin AT cygwin DOT com Subject: gcc version 2.95.3-5 (cygwin special) Anonymous structures allocated wrong. Date: Fri, 13 Jul 2001 11:59:32 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 13 Jul 2001 11:59:32.0587 (UTC) FILETIME=[47357BB0:01C10B93] While I have learned that cygwin now supports anonymous structures which makes some nice things available to me... like derrived structures... I have also recently learned that they do not compile correctly... This program demonstrates the problem //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- typedef struct thing_tag { int x; struct { int bFlag1:1; int bFlag2:1; int bFlag3:1; }; } THING, *PTHING; typedef struct other_tag { THING; int y; } OTHER, *POTHER; OTHER o; PTHING pt = (PTHING)&o; int MemDump( int len, char *p ) { int n; for( n = 0; n < len; n++ ) { printf( "%02x ", p[n] ); } printf( "\n" ); } int main( void ) { pt->bFlag1 = 1; pt->bFlag2 = 0; pt->bFlag3 = 1; pt->x = 0x1234; printf( "%d %d %d %d\n" , pt->bFlag1, pt->bFlag2 , o.bFlag1, o.bFlag2 ); MemDump( sizeof(THING), (char*)pt ); MemDump( sizeof(OTHER), (char*)&o ); pt->bFlag1 = 0; pt->bFlag2 = 0; pt->bFlag3 = 0; o.x = 0x1234; o.bFlag1 = 1; o.bFlag2 = 0; o.bFlag3 = 1; printf( "%d %d %d %d\n" , pt->bFlag1, pt->bFlag2 , o.bFlag1, o.bFlag2 ); MemDump( sizeof(THING), (char*)pt ); MemDump( sizeof(OTHER), (char*)&o ); } //--------------------------------------------------------------------- //--------------------------------------------------------------------- //--------------------------------------------------------------------- The struct { flags }; should be in the same location in both a THING and and OTHER which includes an anonymous THING as it's first element. however, the first print demonstrates that printing pt->flag1 and o.flag1 do not print the same value. Actually in OTHER the int x; and struct { flags }; overlap and all share the same memory... the value printed at the memory dump printf 35 12 00 ... the 35 is 34 plus the 1 bit set by setting o.flag1. Having considered this - I added another element after the flags structure - and it is in the correct location in both structures... it's the anonymous structure containing flags that is moved to offset 0 in the OTHER structure... typedef struct thing_tag { int a, b; int x; struct { int bFlag1:1; int bFlag2:1; int bFlag3:1; }; } THING, *PTHING; typedef struct other_tag { THING; int y; } OTHER, *POTHER; setting flags in OTHER overwrite THING.a ... Perhaps this will give someone who has worked on this enough information... _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/