From: "News Reader" Newsgroups: comp.os.msdos.djgpp Subject: struct bug? Date: Fri, 29 Aug 2003 11:01:56 +0200 Organization: UTA/netway (Customer) Lines: 56 Message-ID: NNTP-Posting-Host: pat-ei.lucent.wellcom.at X-Trace: newsreader1.netway.at 1062147733 29169 195.230.174.18 (29 Aug 2003 09:02:13 GMT) X-Complaints-To: abuse AT uta DOT at NNTP-Posting-Date: 29 Aug 2003 09:02:13 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com /* The following short source does not compile, because Gcc obviously has problems with sizeof("structured type member") . Although there is plenty of workaraound (just use a variable instead of the type), I am still keen to understand why the compiler can handle the entire structure (e.g. 'abt' as stated below), but not a structure member (e.g. 'abt.a'). This looks like a bug to me, but I will gladly accept knowlegeable explanations of someone with more insight than myself. Thanks. */ #include // Types typedef struct { int a; int b; } abt; struct cdt { int c; int d; }; // Vars struct { int e; int f; } ef; struct cdt cd; abt ab; // Main() int main () { printf("\n\n"); printf("Sz(ab): %ld\n", sizeof(ab) ); // These compile, no problem printf("Sz(ab.a): %ld\n", sizeof(ab.a)); printf("Sz(abt): %ld\n",sizeof(abt) ); // this still compiles printf("Sz(abt.a): %ld\n",sizeof(abt.a)); // >>> BUT THIS ONE DOESN'T printf("Sz(cd): %ld\n", sizeof(cd) ); // This is ok, although ... printf("Sz(cd.c): %ld\n", sizeof(cd.c)); // ... we get the error below printf("Sz(cdt): %ld\n",sizeof(cdt) ); // >>> cdt: 'undeclared' ... printf("Sz(cdt.c): %ld\n",sizeof(cdt.c)); // >>> ... compiler tells me printf("Sz(ef): %ld\n", sizeof(ef) ); // vars gave no trouble ... printf("Sz(ef.e): %ld\n", sizeof(ef.e)); // ... just types, sometimes return(0); }