On Dec 8, 2015, at 1:54 PM, Jeff Squyres (jsquyres) <[email protected]> wrote:
There's a working group here at the form who is investigating the possibility of passing C function argument as a struct that contains a union, perhaps something like this:
Not a good idea in my opinion. The whole idea of overlaying memory bits with variables of different types is something that should be limited to low-level system programmers, if even that. They seem to be wanting to do “fake” polymorphism. How would they propose that the callee figure out which of the options to choose, without the infrastructure of “real” polymorphism.
----- struct to_be_passed_as_an_arg { enum actual_type; union { struct { MPI_Comm comm; // ... several more members } comm_stuff;
struct { MPI_Win win; // ... several more members } win_stuff;
struct { MPI_File file; // ... several more members } file_stuff; } obj; }; -----
Can we do this in Fortran? If so, how?
Not really.
Craig suggests that TRANSFER and/or EQUIVALENCE may be helpful here…?
TRANSFER is an executable function. It would not appear as part of a type declaration. EQUIVALENCE, apart from being added to the deprecated list, cannot be applied to component declarations of a type. Cheers, Bill
-- Jeff Squyres [email protected] For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/
_______________________________________________ mpiwg-fortran mailing list [email protected] http://lists.mpi-forum.org/mailman/listinfo.cgi/mpiwg-fortran
Bill Long [email protected] Fortran Technical Support & voice: 651-605-9024 Bioinformatics Software Development fax: 651-605-9142 Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
participants (1)
-
Bill Long