Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!hc!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical anal Message-ID: <3904@lanl.gov> Date: 21 Sep 88 01:57:17 GMT References: <1553@ficc.uu.net> Organization: Los Alamos National Laboratory Lines: 50 From article <1553@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva): > In my ideal syntax, it'd look like this: > >> > char twodarray^[10][10]; >> > twodarray = malloc(sizeof(twodarray^)); >> > twodarray^[9][5] = 'c'; Now, let's add an array syntax to this proposed language, shall we? char static_array [10][10] // my declaration to compare with your // dynamic array. (// is C++ for comment) char twodarray^[10][10]; twodarray = malloc(sizeof(twodarray^)); // your array now exists. Now let's use the array assignment: static_array = 'c'; // all 100 elements set to 'c' twodarray = 'c'; // whoops, just set the pointer instead! // I really meant twodarray^ = 'c'; // set 100 elements to 'c' at location 'c' But now I have to know which type of allocation I am planning _before_ I write the body of the code! Suppose I write the code with all static arrays and then decide that I need to switch to dynamic arrays - your syntax requires me to alter the whole program! The proposed Fortran 8x syntax only requires that I change the declarations and add the allocation call. Furthermore, suppose the _use_ of the array is not local to the declaration: set_array (array) char array [] // what syntax for passed in array? { array = 'c' } I could call set_array with either static_array or twodarray as an argument. The compiler can't know which was which! Your argument about there 'being a pointer there anyway' is wrong. There is a pointer for the statically declared array as well - it's just optimized out during constant folding in the compile. I only need the declaration which explicitly includes a pointer if I plan to change the pointer in ways other than through the ALLOCATE/DEALLOCATE sequence - something I _rarely_ need to do and which I would prefer a different syntax entirely just to remind me that pointers are dangerous like GOTO's are. J. Giles Los Alamos