(j3.2006) Union in Fortran
Bader, Reinhold
Reinhold.Bader
Wed Sep 14 04:34:28 EDT 2016
Hello Malcolm,
Von: j3-bounces at mailman.j3-fortran.org [mailto:j3-bounces at mailman.j3-fortran.org] Im Auftrag von Cohen Malcolm
Gesendet: Mittwoch, 14. September 2016 09:44
An: fortran standards email list for J3 <j3 at mailman.j3-fortran.org>
Betreff: Re: (j3.2006) Union in Fortran
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).
Thanks for pointing this out. I was relying on sequence association, and overlooked the additional rule.
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.
Fully agree. The example was intended as a curiosity (and made up quite some time ago when the topic was raised).
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> [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<mailto: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<mailto: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<mailto: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/eccf758d/attachment-0001.html
More information about the J3
mailing list