I have used the nonstandard LOC() function for some time now with
several compilers. See e.g.:
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gfortran/LOC.html
Although it is not officially in the Fortran standard, it is supported
at least by gfortran, ifort, sunf95 and g95. Now I have the problem
that NAG does *not* seem to support it. So my question is: Does
anybody know if there is a way to use this function (or a replacement)
with NAG? (e.g. Absoft does not support LOC, but has an equivalent
function named POINTER)
Any hints are welcome.
Thanks,
Janus
The NAG compiler contains in my experience only very few vendor
extensions. You could try
use iso_c_bindings
type(c_ptr) :: cptr
cptr = c_loc(...)
and then use "cptr". If you really need an integer, you could try
integer(c_intptr_t) :: ptr
ptr = transfer(cptr,ptr)
TRANSFER should work, but I think it is not guaranteed to work.
Tobias
Yeah, using C_LOC would also have been my next guess for solving this,
if there really is no other way ...
Cheers,
Janus
Call a C function that takes a void * arg, casts it to int or long and
returns that value ? Still implementation defined though according to
section A6.6 of K&R2 even if you can work out the size of integer
thingy you need,
Ian
>> I have used the nonstandard LOC() function for some time now with
>> several compilers. [...]
>> Although it is not officially in the Fortran standard, it is supported
>> at least by gfortran, ifort, sunf95 and g95.
>
> The NAG compiler contains in my experience only very few vendor
> extensions. You could try
> use iso_c_bindings
> type(c_ptr) :: cptr
> cptr = c_loc(...)
> and then use "cptr".
There seems little reason to use LOC() now that c_loc is available. One
non-portability: ifort doesn't check the c_loc() requirement for TARGET
attribute, which you didn't show here.