For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2004 > Re: Void pointer ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Void pointer ?
Michael Metcalf

2004-05-12, 9:08 pm


"Fernando M. Roxo da Motta" <roxo@roxo.org> wrote in message
news:slrnc9lqbq.2ti.roxo@mamaeh.roxo...
>
> Is it possible to do the same in Fortran 9x ?
>


Not legally, as you've discovered. It is always possible to cheat, for
instance by using common, as in

common/a/x
real, pointer :: x(:)
allocate(x(10))
x = 6
call s(size(x))
end

subroutine s(n)
common/a/j
integer, pointer :: j(:)
print *, j(:n)
end

This is not guaranteed to work by the standard (j is formally undefined),
but will on all known compilers (see also "Fortran 90/95 Explained", Section
11.2).

Have you looked at the transfer function (ibid., Section 8.9)? That allows
you to write statements such as

i = transfer(a(j), i)

and is perefectly standard (it was put into f90 with just this applicatioin
in mind).

Hope that helps,

Mike Metcalf


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com