(j3.2006) Union in Fortran
Cohen Malcolm
malcolm
Wed Sep 14 03:43:58 EDT 2016
No, this is not conforming. The pointer assignment ?o => this? is not conforming when the dynamic type is not t. Yes it is theoretically possible for compilers to detect this nonconformance (but none do at the moment as far as I know).
In fact I don?t see the advantage in this design. Just using extensible types instead of sequence types gives you the same facility but actually is standard-conforming and does not rely on the ?tag? being maintained by the user code.
I agree with Steve that using TRANSFER is the usual way of handling things like C unions if you want to be standard-conforming.
From: Bader, Reinhold
Sent: Wednesday, September 14, 2016 1:00 AM
To: fortran standards email list for J3
Subject: Re: (j3.2006) Union in Fortran
See attached code example. Quite clunky, but conforming, I believe.
I think you can do a similar example with BIND(C) types, using the TYPE(*) from TS29113.
Cheers
Reinhold
Von: j3-bounces at mailman.j3-fortran.org [mailto:j3-bounces at mailman.j3-fortran.org] Im Auftrag von Daniel C Chen
Gesendet: Dienstag, 13. September 2016 17:52
An: j3 at mailman.j3-fortran.org
Betreff: (j3.2006) Union in Fortran
Hello,
Is there anyway in Fortran that I can do the equivalence of the following C code?
struct {
int key;
union {
float t;
int value;
}
} s;
Thanks,
Daniel
XL Fortran Development - IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
________________________________________________________________________
This e-mail has been scanned for all viruses by Star.
________________________________________________________________________
--------------------------------------------------------------------------------
_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
http://mailman.j3-fortran.org/mailman/listinfo/j3
--
........................Malcolm Cohen, Nihon NAG, Tokyo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20160914/22225130/attachment.html
More information about the J3
mailing list