Path: utzoo!attcan!uunet!husc6!ukma!nrl-cmf!ames!hc!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: An array by any other name. . . Message-ID: <3698@lanl.gov> Date: 16 Sep 88 19:34:24 GMT References: <13587@mimsy.UUCP> Organization: Los Alamos National Laboratory Lines: 48 From article <13587@mimsy.UUCP>, by chris@mimsy.UUCP (Chris Torek): >>... With the pointer, I _don't_ want the language to apply any >>constraints on where it can point; > None at all? C requires that it point to some integer. ^^^^^^^ Actually a nit-pik here: C requires pointers to always point the an object of the _same_ type as it was declared to be a pointer to. I like this rule - I will accept it. >>with the array I want array bounds checking - that's two different >>semantics folks!!! > > Actually not. You can buy a C compiler (from Sabre) that will > do bounds checking. (It does the checking on pointers, too, > including on pointers to regions allocated by malloc.) Ah, but I don't _want_ it to check for pointers. As long as my pointer addresses something of the correct type, why should the language care _where_ it is? I _want_ the compiler to do bounds checking on arrays and _not_ pointers. >>Furthermore, in C x[i][j] is _supposed_ to be semantically equivalent >>to *(*(x+j)+i). Statically allocated 2-d arrays aren't implemented >>this way! > Ah, but they are. Ah, but they aren't! The syntax above _implies_ that there really _is_ a vector of pointers (indexed by j) which point to vectors of values (indexed by i). This intermediate vector of pointers is dispensed with if the compiler can verify that the array was statically declared. The most obvious way of declaring a dynamic 2-d array will actually cause this intermediate vector of pointers to be defined - this is why such dynamic arrays don't optimize (the pointers in the vector must be assumed to be possibly aliased). Defining 2-d dynamic arrays which _don't_ have this intermediate pointer vector requires more devious declarations (and usually makes the _use_ of the array syntactically different as well). > True, but only with a qualifier. This applies to dynamically > allocated, dynamically *sized* arrays, which simply do not exist in C. > (Neither do they exist in FORTRAN.) Ah, but they _will_ almost certainly exist in the upcomming Fortran. And I'll be willing to bet that the only difference between such dynamic arrays and their static counterparts will be a tag on the declaration and an allocation call. The use will be identical! J. Giles Los Alamos