- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Right now that internal representation gets returned to the calling program (it is just an array of a data type). What I would like to do is hide the internal representation from the calling program and return just a "generic" pointer, much like dss_create() routine does in the Math Kernel Library.
Part of the rationale is philosophical--the calling program shouldn't care about the internal representation, part of it is to minimize recompling if I change the internal representation.
Is this even a good idea to do in Fortran? What is the "best" way for doing this? The definition of "best" means closest to the standard.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, you can reuse (and cheat on) the fact that Fortran scalar POINTERs are 32 (64)-bit entities in all compilers around and provide a mismatch on the argument-lists (i.e. INTEGER, POINTER vs. TYPE(Internal), POINTER); doing so, however, would require deliberate breaking of explicit interfaces provided by the MODULEs.
A possibly better approach is to use ISO_C_BINDING module (which can have legitimate uses even in purely Fortran contexts), and which lets you cast a C pointer to Fortran pointer (C_F_POINTER) and reverse (C_LOC) using a type(C_PTR) as "mediator". It gives you wider portability, but it's not implemented in all modern compilers yet (it is in at least Ifort 10.x, and g95).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a somewhat standard way to call C/C++ from Fortran. If you wish to have your code follow a standard then you could have a C/C++ dummy routine that takes a Reference of one type and returns the handle (void*). Let C/C++ perform the cast.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page