Type punning in C

P E Smee exspes at gdr.bath.ac.uk
Mon Oct 16 20:18:17 AEST 1989


In article <1989Oct16.092936.142 at gdt.bath.ac.uk> exspes at gdr.bath.ac.uk (P E Smee) writes:
>In article <126279 at sun.Eng.Sun.COM> khb at sun.UUCP (Keith Bierman - SPD Advanced Languages) writes:
>>In article <1989Oct11.091619.18336 at gdt.bath.ac.uk> exspes at gdr.bath.ac.uk (P E Smee) writes:
>>
>>
>>>Problem is, the Fortran standard *also* says that if your program tries
>>>to take the value of the variable using a different type than the type you
>>>used when you last stored into it, your program is invalid.  
>>
>>My quick peek into the document (pages 8-3 and 17-1..4ish) doesn't
>>make this obvious to me. Could you please quote chapter and verse ?
>>
In the previous posting, I quoted chapter and verse from the 77 FORTRAN
standard.  The 66 standard is even stricter.  EQUIVALENCE causes things
to become associated (full stop -- no fudging about partial or total
association) and says in 10.2.3.1 (5) [Variables and array
elements become undefined as follows:] When an associated entry
of different type becomes defined.

So, I'd say the 66 standard prohibits it completely, while the 77 standard
allows it in some cases (but only when the variables are not (loosely
speaking) of the same size).  The one interesting case which is explicitly
valid in 77 appears to be EQUIVALENCE of a REAL array of dimension 2 with
an COMPLEX variable, in which case REAL(1) would be the real part of
the COMPLEX and REAL(2) the imaginary part.
-- 
 Paul Smee               |    JANET: Smee at uk.ac.bristol
 Computer Centre         |   BITNET: Smee%uk.ac.bristol at ukacrl.bitnet
 University of Bristol   | Internet: Smee%uk.ac.bristol at nsfnet-relay.ac.uk
 (Phone: +44 272 303132) |     UUCP: ...!mcvax!ukc!gdr.bath.ac.uk!exspes



More information about the Comp.lang.c mailing list