@z This file was created by Aleksandar Donev as part of the Sphere Packing Project. Feel free to use any portion of it and contact me at adonev@princeton.edu @x \Title{Emulation of \tt{ISO\_C\_BINDING} in Fortran 95} \author{Aleksandar Donev} \date{\today} \maketitle @*0 Support for module |ISO_C_BINDING| in C. @*1 Pointer conversion. @a #include void* _MangledProcedure(F_C_POINTER_C) (void** f_pointer) { return(*f_pointer); } void* _MangledProcedure(F_C_PROCEDURE_C) (void* f_pointer) { return(f_pointer); } void _MangledProcedure(C_F_POINTER_C) (void** c_pointer, void** f_pointer) { *f_pointer=*c_pointer; } @@; @*1 Finding strides between array elements. Since Fortran arrays can be strided, it is useful to have a mechanism to find the stride (distance in the length of the unit type) between two array elements. C's pointer arithmetic gives us exactly this with just a simple subtraction. @m _STRIDE_C_Body(type_,kind_) @; int _MangledProcedure(STRIDE_C_@e@&kind_) (type_* var1, type_* var2) { return(var2-var1); } @m _STRIDE_C_Body_T(number_) @; _STRIDE_C_Body(_AllCTypes(number_),_AllCKinds(number_)) @; @= _GenerateBody_TK(N_TC_ALL,_STRIDE_C_Body_T) @; @ @I Macros.hweb @I C_Interop.hweb @%% EOF