J3/03-256r1
Date: 14 November 2003
To: J3
From: Aleksandar Donev
Subject: Post Fortran 2003: Type aliases
Response is in J3/03-277
______________________________________
Summary
______________________________________
I believe that Fortran should provide some form of type aliases. They were
deleted from the draft because of problems with the original design and lack
of time. I explain below why they are needed, other then saving keystrokes or
writing clearer code.
______________________________________
Motivation
______________________________________
Consider writing a Fortran interface to the MPICH implementation of MPI.
Typically, this will be a module that contains various constants, type
parameters, and interfaces. MPI uses many typealiases, which are needed when
writing interfaces. For example, MPI_Datatype is typically an alias for int.
But one cannot assume this, nor that it is indeed an integer. One cannot get
away with our untyped C_PTR, since arguments of type MPI_Datatype are passed
by value, not by reference. It is necessary for any kind of portability that
one be able to write:
TYPEALIAS :: MPI_Datatype=>INTEGER(KIND=C_INT)
in the module for the interface to MPICH.
This kind of situation occurs in almost all C libraries I have interfaced
with. I typically use macros to hide what exactly something like MPI_Datatype
is. It is a shame that Fortran 2003 did not make interfacing to C possible
without preprocessing or other dirty tricks!