Path: utzoo!attcan!uunet!yale!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical anal Message-ID: <3826@lanl.gov> Date: 20 Sep 88 19:06:26 GMT References: <447@quintus.UUCP> Organization: Los Alamos National Laboratory Lines: 51 From article <447@quintus.UUCP>, by ok@quintus.uucp (Richard A. O'Keefe): > In article <3746@lanl.gov> jlg@lanl.gov (Jim Giles) writes: >>No, I still like the Fortran 8x stuff better: >> ALLOCATABLE, CHARACTER::TWODARRAY(:,:) >> ... >> ALLOCATE (TWODARRAY(10,10)) >> ... >> TWODARRAY(5,9) = 'c' > ... > if I try to use it before executing the allocate statement I'll end up > with an undefined reference (and that's a property of _pointers_), and > the allocate statement is _only_ applicable to pointers, not to ordinary > arrays. The name TWODARRAY is used in *some* contexts to refer to the > pointer variable (allocate and free) and in *other* contexts to refer to > the thing pointed to. "separate and distinct"? This is the proposed syntax in Fortran 8x. Fortran 8x _HAD_NO_POINTERS_!! So, rather obviously, the allocate statement is _NOT_ applicable to pointers at all. Further, TWODARRAY is an identifier. Like _all_ identifiers, it has certain attributes (data type, dimensionality, SAVE/automatic, EXTERNAL/local/COMMON, etc.). In the above example, I gave a local array identifier two more attributes: allocatable and uninitialized. The allocate statement changed the second attribute to initialized and added explicit sizes to the array attributes. In any case, TWODARRAY _always_ refers to an array. The above doesn't confuse arrays and pointers - doesn't even mention pointers. It introduces a _new_ type of array - one that can be allocated dynamically. 'Undefined reference' may be _a_ property of pointers, not not a property exclusive to pointers! Other things can be undefined at various times during the execution of a program. Being represented as a binary number is also a property of pointers - and everything else in most machines. Note: arrays and pointers _do_ have one thing in common - they can each be implemented using the other. I did dynamic memory in the early '70s using an array (called MEM) located at the end of my memory image. The system had a call which allowed me to change field length (rather like brk()). I wrote routines which allocated and freed blocks of memory within the MEM array and returned 'pointers' to me in the form of array indices (rather like malloc() and free()). To reference a dynamically allocated array area I wrote 'MEM(A+I)' - if you think of 'MEM' as a '*', 'A' as a pointer and 'I' as an index, this is the exact same syntax as C arrays/pointers. I was dissatisfied with this 15 years ago, and I'm not pleased with it in C now. (By the way, this was the most common way of doing dynamic memory in Fortran until about 8 years ago when most large scientific programming installations managed to get pointers installed in their Fortran compilers.) J. Giles Los Alamos