Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!elf115!rec From: rec@elf115.uu.net (Roger Critchlow) Newsgroups: comp.lang.c Subject: Re: Help, page 197 K&R !!! Message-ID: <155@elf115.uu.net> Date: 6 Jul 89 10:51:01 GMT References: <646@kl-cs.UUCP> <236100020@mirror> Organization: ELF, Sea Cliff, NY Lines: 33 In article <236100020@mirror>, pat@mirror.TMC.COM writes: >>/* Written 3:25 am Jul 2, 1989 by gwyn@smoke.UUCP in mirror:comp.lang.c */ >>In article >>cline@sun.soe.clarkson.edu (Marshall Cline) writes: >>> { char *p; >>> p->squiggle = 3; /* implicit cast of "p" to "(worm_t *)p" */ >> >>I don't think that was ever allowed; some older C compilers did permit >>pointers to one structure type to be used to access members of another >>structure type, but that's as weird as I recall it getting. > >I agree that this is weard and it is bad programming practice, but is >it possible that if the programmer knew what he was doing should it be >okay for him to do it? It got weirder still. So long as the structure member had a unique offset, the member could be referenced from any pointer or from any lvalue. Thus you could do this: is_an_int_value(l) long l; { struct halves { int high, low; }; return (l.high == -1 || l.high == 0); } If the programmer knew what he was doing, it should be okay? But how do _you_ figure out whether the programmer knew what he was doing when you find his code after he's gone? If the programmer knows what he's doing, then he'll write the necessary casts, and get the word order right on the first or second try. :-) -- rec@elf115.uu.net --