Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!rutgers!bellcore!att!cbnews!maddog From: maddog@cbnews.ATT.COM (john.j.tupper) Newsgroups: comp.lang.c Subject: Re: Is this a bug in some C compilers? Keywords: bug; cc; referencing a pointer as if it were a structure Message-ID: <8436@cbnews.ATT.COM> Date: 19 Jul 89 21:07:49 GMT References: <800@sbsvax.UUCP> Reply-To: maddog@cbnews.ATT.COM (john.j.tupper) Organization: AT&T Bell Laboratories Lines: 33 In article <800@sbsvax.UUCP> greim@sbsvax.UUCP (Michael Greim) writes: > printf ("Value 5 has been put at address %1d\n", &(t.count)); > .... >Am I correct to say that the program is not correct C, and that all compilers >which compile it are wrong? Michael is complaining about the fact he got away with writing t.count when t was a pointer (the compiler should have insisted on t->count). K&R C treats member names as offsets. I.e. fred.foo turns into *(&fred + offset_to_foo). What's more (this is the braindamaged part) member names are global across all structures. This means the following is correct: struct a { int a_mem; }; struct b { int b_mem; } one_b; one_b.a_mem = 0; As illistrated by Michael's example, the variable you take a member of doesn't even have to be a structure at all! K&R don't actually and say this, but they do allude to it. On page 197, paragraph 5, it says that two structures may have the same member name it the member is the same type and at the same offset in both structs. Some C compilers retain this bogisity, some fixed it. -------------------------------------------------------------- sdfl sdf sldkf sdlfoi My real signature is illegible too.