On Wed, Mar 6, 2013 at 10:35 AM, Thomas Koenig <tkoe...@netcologne.de> wrote: > Am 04.03.2013 21:34, schrieb N.M. Maclaren: > > (quoting documentation about DEC UNIONs for Fortran) > >> "However, if you overlay one variable with another smaller variable, >> that portion of the initial variable is retained that is not overlaid. >> Depending on the application, the retained portion of an overlaid variable >> may or may not contain meaningful data and can be utilized at a later >> point in the program." > > > Ouch. > > This seems to be at odds with C's unions, where it is not allowed to do > type punning.
Except GCC implements C's unions as allowing to do type punning as an extension and as far as GCC is concerned that is not going to change any time soon. This is a documented exception to the aliasing/type punning rules. Thanks, Andrew Pinski > > This probably means that it would be necessary to present a DEC Fortran > union to the middle end as something like > > union { > char buff[8]; > double b; > int c; > } > > and then only do assignment with memcpy() to buff. > > I think you're right - if we add this to gfortran, it should live behind > > -fdo-you-really-want-to-use-dec-unions-yes-well-in-that-case-i-ll-let-you > > or an options with a similar name. > > Thomas