Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.society.futures Subject: Re: C's sins of commission (was: (pssst...fortran?)) Message-ID: <63751@lanl.gov> Date: 21 Sep 90 20:27:58 GMT References: <1990Sep21.193403.20381@abcfd20.larc.nasa.gov> Organization: Los Alamos Natl Lab, Los Alamos, N.M. Lines: 57 From article <1990Sep21.193403.20381@abcfd20.larc.nasa.gov>, by jcburt@ipsun.larc.nasa.gov (John Burton): > In article <63722@lanl.gov> jlg@lanl.gov (Jim Giles) writes: > [...] >>Hear, Hear!! I like a programming language to allow me to say what I >>mean - not to have to convert my algorithm into something cryptic. >>However, C forces me to encrypt my programs - I can't use arrays, I >>have to encrypt them as pointers; I can't use dynamic memory, I have >>to encrypt them as pointers; I can't use mapping (run-time equivalence), >> [...] >> > Excuse me? are you REALLY saying you CAN'T use arrays in C without > resorting to pointers??? I'm confused. Does this mean that I can't > use the statement > a[i][j] = 123; Syntactic suger. Try sending the array to a subroutine as a parameter. Then you'll find out what the array _really_ is. Try referencing the array in the subroutine with the above statement - lots of luck. What I want is an array that _stays_ an array when I pass it around. Arrays that have to be locally declared or global are practically useless for programs which do any serious array manipulation. For them, arrays in C are not anthing but another name for pointer. > Can't use dynamic memory without using pointers? Again, I assume that's > not *really* what you mean...I can send you code to create 2,3,... > whatever Dimensioned array you want from the heap (using malloc & > calloc) that can be used in any situation where you use a statically > declared one (I have yet to find a situation where it doesn't work) > using exactly the same syntax. It works on all the compilers mentioned > above using the ANSI standard mode. I use this routine regularly in > the image processing work I do...the only problem I've run into is > running out of memory for 2-D arrays larger than 1024x1024 of type > float. Ok. Now give me code in which those declarations resemble static array declarations in any significant way. The declaration of a dynamic object should be _identical_ to the declaration of a static object of the same type (with the possible exception of place-holders for the information to be filled in at allocation time). Once you've failed to do that. Then you can tell me how the compiler knows that the pointers (hidden under your clever declarations) are to dynamic objects and are not aliased to _any_ other pointers. In order to get any kind of efficiency, the compiler must be able to detect aliasing so that it can optimize non-aliased references. However, as far as the compiler knows, the result of a malloc() or calloc() call is just any old pointer, could be aliased to anything. No, the techniques you are advocating (which I've seen before and dismissed for the same reasons) merely hide the facts. This is doubly cryptic - you are pretending to be arrays when you're really using pointers, and you are using pointers because the language doesn't really have arrays. I still prefer to tell the compiler straight out what it is I want to do. J. Giles