Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ginosko!aplcen!haven!adm!cmcl2!lanl!beta!dac!matthias From: matthias@mpx1.lanl.gov (Bjorn E. Matthias, M/S H831, 7-6241 or 7-7906) Newsgroups: comp.lang.fortran Subject: Re: Type punning in FORTRAN (was in C) Message-ID: <1131@mpx1.lanl.gov> Date: 15 Oct 89 19:18:41 GMT References: <475@idacrd.UUCP> <1989Oct10.185851.6490@agate.berkeley.edu> <1989Oct11.091619.18336@gdt.bath.ac.uk> <1654@l.cc.purdue.edu> <1989Oct13.090311.9760@gdt.bath.ac.uk> <1874@sunset.MATH.UCLA.EDU> Organization: LAMPF Data Analysis Center, Los Alamos NM Lines: 38 In article <1874@sunset.MATH.UCLA.EDU>, pmontgom@sonia.math.ucla.edu (Peter Montgomery) writes: > In article <1989Oct13.090311.9760@gdt.bath.ac.uk> exspes@gdr.bath.ac.uk > (P E Smee) writes: >> >>The need for a construct to permit type punning is clear, particularly >>if you're doing 'systemmy' work. >> >>This provides an explicit instruction to the compiler, and (more >>importantly) a warning to future maintainers of the code, that you are >>about to willfully, knowledgeably, and intentionally, cheat the data >>typing and conversion rules. Every serious language should have such a >>thing. (Unfortunately, it seems that most don't, sigh...) >> > If I read the June, 1989 draft F8X correctly, then the > new TRANSFER intrinsic function (p. 13-51, section 13.13.108) > will do precisely this. The syntax is > > result = TRANSFER(SOURCE, MOLD, SIZE) . > > It "returns a result with a physical representation identical to that > of SOURCE but interpreted with the type and type parameters of MOLD." > The last argument, SIZE, is optional and affects the array shape > of the result when SOURCE and MOLD have different sizes > (e.g., double precision and character). > If I am not mistaken, then this could be previously accomplished in VAX FORTRAN with EQUIVALENCE between two variables of whatever types. I have used this often and it appears that TRANSFER is different only in that one truly has *two* pieces of data, two memory locations. Sounds like a useful function, though I do not believe it really introduces a "new" feature. Forgive me if I am stating what is obvious to all others. Regards, Bjorn Matthias BITNET : MATTHIAS@LAMPF