next up previous 252
Next: More on Calling FORTRAN from C
Up: Pointers
Previous: Accessing Dynamic Memory from C and FORTRAN


Registering Your Own Pointers

CNF also provides two functions, cnfRegp and cnfUregp, for registering and un-registering pointers - i.e. for entering and removing them from the internal table which is used for pointer conversion between C and FORTRAN. You will probably never need to use these, since pointer registration is normally managed completely automatically by the memory allocation functions which CNF provides.

The reason for providing them is that there may be ways of creating new memory, for which cnfMalloc or cnfCalloc cannot be used. For example, mapping data files directly into memory. If the resulting C pointers are to be exported to FORTRAN, they must be accessible to CNF for conversion purposes, so they must be registered in CNF's internal table.

If you should ever need to use this facility, then the main point to note is that attempting to register a C pointer can potentially fail (cnfRegp returns -1 to indicate this). This will occur if, when the C pointer is converted to a FORTRAN INTEGER, it clashes with a FORTRAN pointer value which is already in use. In such a case you cannot safely export your pointer to FORTRAN, so you must obtain a new pointer and re-register it. Typically, this may involve allocating a new block of memory at a different location and freeing the original. The consolation is that such clashes are extremely rare.



next up previous 252
Next: More on Calling FORTRAN from C
Up: Pointers
Previous: Accessing Dynamic Memory from C and FORTRAN

CNF and F77 Mixed Language Programming -- FORTRAN and C
Starlink User Note 209
P.M. Allan
A.J. Chipperfield
R.F. Warren-Smith
19 January 2000
E-mail:ussc@star.rl.ac.uk