Code Comments
Programming Forum and web based access to our favorite programming groups.In article <87ekig1p2r.fsf@vega.site>, Richard Maine <nospam@see.signature> writes >Andy Vaught <andy@firstinter.net> writes: > > >Yes, making these completely equivalent makes it impossible to do >bounds checking on arrays that actually *DO* have bounds of 1. Such >arrays exist. Disabling bounds checking on them would be a shortcomming. > >I've seen compilers where there were command-line switches to enable >this hack. If one feels the need to support bounds checking for old >codes with this hack, I'd say that made a lot more sense than >crippling bounds checking so that it can never work on some arrays. > I don't follow this. If you treat DIMENSION X(1) as DIMENSION X(*) and an array with one element in it is passed, it's perfectly possible to have a bounds check which fails if the subroutine references X(2). There are, and have been for years, compilers which do bounds-checking on arrays with bounds of * (this is one of the tests in the Polyhedron benchmarks). The only problem I can see is that if you always treat 1 as *, you lose the possibility of a check as to whether you passed an array of size 2 to a subroutine where it is declared explicitly as size 1 and was actually supposed to be size 1. Both you and the compiler would have to be psychic to pick this one up in any case. Catherine. -- Catherine Rees Lay To email me, use my first name in front of the "at".
Post Follow-up to this messageCatherine Rees Lay wrote: (big snip on dimension of (1) in various places) > I don't follow this. If you treat DIMENSION X(1) as DIMENSION X(*) and > an array with one element in it is passed, it's perfectly possible to > have a bounds check which fails if the subroutine references X(2). I hadn't noticed that, either. I am not sure what any version of the standard says about non-matching dimensions in subroutines and subroutine callers. > There are, and have been for years, compilers which do bounds-checking > on arrays with bounds of * (this is one of the tests in the Polyhedron > benchmarks). Well, it does get complicated in some of the cases being discussed. Some other languages commonly use call by descriptor for arrays, allowing the full dimension information to be passed, but not allowing some of the other Fortran tricks that have been described here. It should be possible, and not all that hard with the computer power available to do this. One could even use the trick of a link time fixup I described earlier. Ugly, but it works. > The only problem I can see is that if you always treat 1 as *, you lose > the possibility of a check as to whether you passed an array of size 2 > to a subroutine where it is declared explicitly as size 1 and was > actually supposed to be size 1. Both you and the compiler would have to > be psychic to pick this one up in any case. -- glen
Post Follow-up to this messageCatherine Rees Lay wrote: > In article <87ekig1p2r.fsf@vega.site>, Richard Maine > <nospam@see.signature> writes > > I don't follow this. If you treat DIMENSION X(1) as DIMENSION X(*) and > an array with one element in it is passed, it's perfectly possible to > have a bounds check which fails if the subroutine references X(2). > > There are, and have been for years, compilers which do bounds-checking > on arrays with bounds of * (this is one of the tests in the Polyhedron > benchmarks). > > The only problem I can see is that if you always treat 1 as *, you lose > the possibility of a check as to whether you passed an array of size 2 > to a subroutine where it is declared explicitly as size 1 and was > actually supposed to be size 1. Both you and the compiler would have to > be psychic to pick this one up in any case. There are two levels to the bounds checking problem. The first level is whether the subscripts are within the bounds that are declared for the array, whether it is an argument or not. The second level is whether the declaration of a dummy argument is compatible with the actual argument supplied. The first level is easy and the second level is hard, under the assumption of an implementation which is trying to add subscript checking on as an after thought. WatFor, Salford etc show that it is easy if the checking is designed in. In the after thought scheme a "*" often translates into don't bother. The historical side confusion is that since the last dimension is "irrelevant" for an argument in some implementations the habit had grown up of supplying anything for the last dimension, which was tamed to using "1" and then formalized to "*". F90 changed everything with ":" and even permitted multiple ":"s while F77 permitted only one "*" and it had to be the last dimension. Supporting ":" before it was introduced was the secret behind WatFor, Salford etc. Different terminology for the same notions, and subject to different technical requirements > Catherine.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.