To: J3 J3/18-275 From: Malcolm Cohen Subject: real-complex interoperability Date: 2018-October-16 Reference: 18-254 1. Introduction There are some difficulties modernising old code that EQUIVALENCEs REAL and COMPLEX, in particular REAL and COMPLEX arrays. Paper 254 described one approach to alleviating those difficulties. This paper describes a method available since Fortran 2003 that can be used to similar effect. 2. The method Old code: REAL X(100) COMPLEX Y(50) EQUIVALENCE(X,Y) New code: Use Iso_C_Binding Real, Allocatable, Target :: x(:) Complex, Pointer :: y(:) Allocate(x(100)) Call C_F_Pointer(C_Loc(x),y,[Size(x)/2]) Although it might be considered a bit weird to use the C interoperability features to do a Fortran thing, it is not really unusual for the C interop features to work well on low-level fiddling, and indeed that was one of the goals (even when not interoperating with C) from the start. This would appear to be an acceptable approach, especially when in many (though not all) cases it would only be an interim solution until the code is fully modern. ===END===