Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Re: pointers to arrays

Jugoslav_Dujic
Valued Contributor II
791 Views
AFAIK no, at least not in the sense you'd like. This is an inherent limitation -- pointers are expressed via array descriptors, which are hidden structures of several bytes, containing starting address, offset and step for each dimension (see documentation for exact Compaq format). For the way you'd like to use pointers, the required information simply cannot fit into that structure.

You might workaround it using your own function. Didn't try the following code but that should be along these lines:

 
SUBROUTINE ASSOCIATE (ptrArray, IndexArray, targetArray) 
 
REAL, POINTER:: ptrArray(:) 
INTEGER::           IndexArray(:) 
REAL, TARGET:: targetArray(:) 
 
IF (ASSOCIATED(ptrArray)) ... 
   !Allocation/deallocation exception handling here 
END IF 
ALLOCATE(ptrArray(SIZE(IndexArray))) 
DO i=1,SIZE(IndexArray) 
    ptrArray(i) = TargetArray(IndexArray(i)) 
END DO 
 
END SUBROUTINE ASSOCIATE 


You have to be very careful about memory management & leaks. There also should be an equivalent routine for freeing memory. Note that you have to allocate/deallocate memory for yourself and that the technique is not very efficient.

An (probably more efficient) alternative, of course, would be to stick to DO-loops
without making a copy as above.

HTH

Jugoslav
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
791 Views
Sorry, rereading my own post I see I wasn't very clear.

Problem with the approach above is that ptrArray is a POINTER only by sintax, not by essence -- if, say, TargetArray changes, ptrArray won't change, since it points to a copy, not to 'real' TargetArray. What I meant under DO-loops is to simply avoid referencing TargetArray via ptrArray and use double-indexing instead at every occurence, i.e. TargetArray(IndexArray(i)). Note that TargetArray(IndexArray) (array-valued) construct is also allowed.
0 Kudos
Reply