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 analysis Message-ID: <3570@lanl.gov> Date: 14 Sep 88 18:38:09 GMT References: <1457@valhalla.ee.rochester.edu> Organization: Los Alamos National Laboratory Lines: 33 From article <1457@valhalla.ee.rochester.edu>, by davis@galaxy.ee.rochester.edu (Al Davis): > Well, what is wrong with an array of pointers? Having worked with both, I > believe the array of pointers is the superior method. It eliminates the ^^^^^^^^^^^^^^^ > conformant array fudge. It is usually faster. It is more general. It ^^^^^^^^^^^^^^^^^^^^ > works for strangely shaped sparse matrices. Etc. I agree with everything above except the marked portions. If I want an array of pointers to pointers to ..., I should do something different from just declaring a two dimensional array - arrays of pointers aren't the same! For one thing, they are almost always slower - they can _never_ be faster because a conformant array _can_ be implemented that way if necessary. An array of pointer to pointer to ... _can't_ be treated as a conformant array though - some of the pointers might be aliased! The fact that they usually aren't doesn't help, the optimizer must assume that it's possible. Someone claimed that interprocedural alias detection will soon be simple - I haven't seen it yet. In any case, even inter- procedural analysis doesn't help if the array isn't constructed until run-time - the compiler can only do things like unrolling loops if it knows _at_compile_time_ that there are no aliased arrays involved. In short, any optimization possible for arrays of pointer to... is also possible for conformant arrays. The reverse is _not_ true. Admittedly, the pointers are more powerful and more general, but if your application doesn't need the power or generality of pointers, you probably would prefer the more optimal conformant arrays. Indeed, it's possible to extend Fortran to include pointers (the Fortran I use has them), it's very difficult to get conformant arrays in C - even when that's what you really want! J. Giles Los Alamos