Path: utzoo!utgpu!watserv1!watmath!att!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!netnews.upenn.edu!msuinfo!rang From: rang@cs.wisc.edu (Anton Rang) Newsgroups: comp.lang.misc Subject: C vs. FORTRAN aliasing Message-ID: Date: 18 Nov 90 21:01:13 GMT Sender: news@msuinfo.cl.msu.edu Organization: UW-Madison CS department Lines: 33 Another thread I probably should avoid.... Suppose that I have a FORTRAN subroutine which takes two parameters which it may modify, X and Y. Assume that the array A is declared somehow; exactly how isn't important. Suppose you have the code: SUBROUTINE BLAH(X,Y) INTEGER X,Y X = 3 Y = 2 IF (A(X) .EQ. 0) ... Translating this to C, you get: blah(int *x, int *y) { *x = 3; *y = 2; if (a(*x) == 0) ... A compiler for FORTRAN can optimize the test to be A(3) since it knows that the assignment to Y can never change X. A compiler for C, in the absence of interprocedural aliasing information, cannot do the same. The interprocedural aliasing problem is NP-hard in the presence of multi-level pointers or reference parameters (sorry, my refs are at home right now, but if any cares e-mail me), and so various approximation algorithms are used. For any approximation algorithm, I can write (pathological) FORTRAN code which will result in worse code being generated by the C compiler. Anton +---------------------------+------------------+-------------+ | Anton Rang (grad student) | rang@cs.wisc.edu | UW--Madison | +---------------------------+------------------+-------------+