Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!haven!adm!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.lang.misc Subject: Unions improve aliasing analysis; EQUIVALENCEs hurt it Message-ID: <1990:Apr1119:39:5690@stealth.acf.nyu.edu> Date: 11 Apr 90 19:39:56 GMT References: <8960014@hpfcso.HP.COM> <14334@lambda.UUCP> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 20 X-Original-Subject: Re: Cheap implementations of languages X-Original-Original-Subject: Re: Pointers and poor implementations In article <14334@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes: [ various stuff, including another implication that C's unions are ] [ as painful to analyze/implement as Fortrans' EQUIVALENCE statement ] Sorry, Jim, you're wrong on this one too. It's only valid to use a union element if that element was assigned to most recently. (This brings up a few pet peeves of mine, but never mind.) I believe a compliant compiler can implement union as struct---though I wouldn't want to use such a compiler if I cared about memory or if I had to look at the internal representation of data. In contrast, EQUIVALENCE is a real pain to analyze. To put it differently, you can regard ``union'' as the assertion ``I'll never use element X unless my last assignment to elements of this union was to X. Same for Y. Same for Z.'' This lets compilers save on memory and improves---not hurts---aliasing analysis. EQUIVALENCE makes no such guarantees; hence C is easier to optimize than Fortran in this respect. Shall we start flogging this horse too? ---Dan