Xref: utzoo comp.lang.fortran:775 comp.lang.c:10783 Path: utzoo!attcan!uunet!husc6!cmcl2!lanl!beta!jlg From: jlg@beta.lanl.gov (Jim Giles) Newsgroups: comp.lang.fortran,comp.lang.c Subject: Re: Should I convert FORTRAN code to C? Summary: complex and arrays Keywords: language conversions, FORTRAN, c Message-ID: <20340@beta.lanl.gov> Date: 17 Jun 88 18:49:06 GMT References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> Organization: Los Alamos National Laboratory Lines: 65 In article <224@raunvis.UUCP>, kjartan@raunvis.UUCP (Kjartan Pierre Emilsson Jardedlisfraedi) writes: > Now here there seems to be a little misunderstanding. I have never > understood why Fortran users keep saying that array indexing is awkward > in C. > [...] Awkward isn't the problem. I don't like the double bracket notation, but anyone can write a macro to turn ARRAY(i,j,k) into array[i][j][k]. The Problem is that 2-d arrays are not optimizable because they are immediately turned into pointer-to-pointer-to-data type of constructs. > If the array had been initialized with Create2DArray() then indexing > would be just as normal,i.e: > > DoSomething(array,m,n) > double **array; > int m,n; > { > ... > array[ i+k ][ j-i ]= 1.0; > ... > } If your use of array here is in a loop (that might otherwise be vector- izable), the C compiler can't vectorize it because a pointer-to-pointer 'may' contain a vector dependency - the compiler doesn't know it's a 2-d array! (If you don't have a vector machine, the problem still exists, you can't unroll the loop for a pipelined archetecture because of the same possible dependency.) This problem is the reason that so much discussion on this news group has recently been about 'noalias' in C (not exactly an appropriate topic for comp.lang.fortran, but relevent to this particular issue anyway). > [...] > ii) You can define your own data structures, which can be any > combination of system defined structures and user defined > structures, array of structures, self-referential > structures and so on. [...] This capability is NOT an adequate replacement for the complex data type. Complex is more than just a pair of reals, there are several operations defined on complex (like plus) which should work naturally. No use of C programming constructs can do this: COMPLEX CVAR REAL RVAR INTEGER IVAR ... CVAR=(CVAR+RVAR)*IVAR ... The operations (including the mixed-mode type conversions) are all done IN-LINE and efficiently. C provides no way to even do this calculation without function calls. > This is not meant as an artillery in the Language Wars, but rather as an > explanation and maybe a clarification for those who haven't had any special > experience with C ,and still think that indexing doesn't exist in C and that > C is bad because it doesn't have the complex data type! Clarifications which contain false or misleading information don't clarify anything. In fact, such 'clarifications' DO add to the Language Wars in very unproductive ways. J. Giles Los Alamos