Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!hub.ucsb.edu!ucsbuxa!3003jalp From: 3003jalp@ucsbuxa.ucsb.edu (Applied Magnetics) Newsgroups: comp.lang.fortran Subject: Fun with pointers (long-ish) Keywords: fortran pointer dynamic data structure Message-ID: <6243@hub.ucsb.edu> Date: 7 Sep 90 19:01:43 GMT Sender: news@hub.ucsb.edu Distribution: comp Lines: 44 Preamble: suppose I do this in a subroutine: integer bcbase ! "Blank Common BASE" common//bcbase integer link(0:3), nwords(0:0), content(0:0, 1) equivalence (link,bcbase), (nwords,link(1)), (content,link(2)) And, in the main program, integer scratch(1000000) ! one million common//scratch Now I can have the routine divide the blank common into unequal-sized blocks, and link them in a list. If a block of N words begins at offset P in blank common, I set up link(P)= nwords(P)= N content(P,k)= The equivalence statements force the memory layout to be what I want. Link(P) is at offset P; nwords(P) is at offset P+1; content(P,k) is at offset P+2+(k-1). More generally, I can use integer offsets into blank common as substitute for pointers; I can imitate C's operator "->" and dereference mock-pointers to structure components; I can manage nontrivial data structures dynamically, as long as the primitive types are restricted to integer, logical, real or double precision (more tricks needed for the latter). Critical assessment: The ANSI standard says that overrunning arrays like I do produces undefined results (17.1.2). THIS IS A CASE OF USING THE WRONG LANGUAGE. DO NOT TRY IT AT HOME. I actually wrote code that way, but only because I have to. I'll be migrating away from it the first chance I get. End of preamble. Question: Assuming that any run-time checking of array bounds can be defeated, are there extant implementations of Fortran that would foil my evil designs? Just curious. --Pierre Asselin, Applied Magnetics Corp.