> Date: Fri, 14 Nov 1997 19:11:53 +0100
> From: Pierre Hugonnet <[log in to unmask]>
> David B. Serafini wrote:
> > I don't see this as a problem that is difficult enough to warrant a
> > special exemption in the standard. C has this problem in spades,
> > and compiler writers deal with it without much trouble.
> >
> > At worst the compiler will have to recognise the special case and
> > generate different code for it (not _much_ different, just one additional
> > indirect reference through the array of pointers). The compiler can
> > identify the special case because it knows the types of all the pieces
> > at compile time.
> >
> > -David
> I think that the two implementation would be _very_ different:
> type test
> integer :: foo
> integer,pointer :: bar
> end type test
> type (test) zap(100)
> Here one can assume a regular pattern for the storage of each foo
> element, so
> that one can point easily to the array zap(:)%foo.
> But each bar element is allowed to point to any memory location, and
> when you
> point to bar you don't point to the pointer itself but to the integer
> pointed by bar.
> This means that zap(:)%bar would be a pointer to an array of irregularly
> distributed
> integers in the memory (such an array is not allowed, I guess).
> In fact we need pointers to pointers to make zap(:)%bar possible .
I disagree. The low-level code the compiler has to generate for nonpointers
would look something like:
!------------
! <setup constants (size_of_zap, base_address, end_address) based on addresses and array sizes>
addr <- base_address
loop:
addr <- addr + size_of_zap
load addr
! do something with zap(i)%bar
if addr == end_address goto exit:
goto loop
exit:
!------------
The low-level code for the pointer case would look something like:
!------------
! <setup constants (size_of_zap, base_address, end_address) based on addresses and array sizes>
zaddr <- base_address
loop:
zaddr <- addr + size_of_zap
load from zaddr to register
load from register
! do something with zap(i)%bar
if zaddr == end_address goto exit:
goto loop
exit:
!------------
As I said, this _will_ run slower. But the complexity of compiling
this code is not high.
-David
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|