Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LOC() and the NAG compiler

1 view
Skip to first unread message

Janus Weil

unread,
Apr 21, 2009, 4:01:05 AM4/21/09
to
Hi all,

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

Tobias Burnus

unread,
Apr 21, 2009, 4:22:49 AM4/21/09
to
Janus Weil wrote:
> Hi all,
>
> 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. 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)

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

Janus Weil

unread,
Apr 21, 2009, 4:58:48 AM4/21/09
to Tobias Burnus

> 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.

Yeah, using C_LOC would also have been my next guess for solving this,
if there really is no other way ...

Cheers,
Janus

Ian Bush

unread,
Apr 21, 2009, 5:32:50 AM4/21/09
to

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

Tim Prince

unread,
Apr 21, 2009, 10:01:17 AM4/21/09
to
Tobias Burnus wrote:
> Janus Weil wrote:

>> 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.

0 new messages