[comp.lang.misc] Unions improve aliasing analysis; EQUIVALENCEs hurt it

brnstnd@stealth.acf.nyu.edu (04/12/90)

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