Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!sdd.hp.com!wuarchive!udel!haven!adm!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.misc Subject: Re: Whether cc after f2c can optimize arrays as well as f77 can Message-ID: <5957@lanl.gov> Date: 14 Nov 90 21:28:28 GMT References: <4962:Nov1405:45:5090@kramden.acf.nyu.edu> Organization: Los Alamos Natl Lab, Los Alamos, N.M. Lines: 74 From article <4962:Nov1405:45:5090@kramden.acf.nyu.edu>, by brnstnd@kramden.acf.nyu.edu (Dan Bernstein): > [...] >> > [ int a; main() { ... sub1(&a); } ] >> > [ sub1(x) { ... sub2(x); sub3(x); } ] >> > [ int a; sub2(y) { ... } ] >> > [ int b; sub3(z) { ... } ] >> > Now a and b are GLOBAL! My solution DOES detect what aliasing goes on! >> Really? I'm sorry. I don't see it. > > Fortran does not have separate compilation like C. [...] Fortran has _only_ separate compilation. It's C that is allowed to compile several routines in the same file as a unit. In Fortran, even if the source of several routines are in the same file, the compiler _must_ process each of them independently. > [...] It does not have > static variables like C. [...] Irrelevant, since this example has no private variables (which C rather peculiarly calls 'static'). > [...] Hence a and b are visible throughout---though > your C version does not reflect this accurately. [...] Huh? It's separate compilation which makes a and b _invisible_ to those functions that don't use them. Or, are you saying that a legal C version of sub1() _must_ mention a and b (even though it doesn't use them)? I assure you that _no_ C compiler in existence requires this. Certainly such a requirement would violate both ANSI and K&R. > [...] The partitions for > sub1() include a and b, as do the partitions for sub2() and sub3(). What? How does the compiler even _know_ about a and b when it compiles sub1()? The file containing sub1() doesn't even mention them. How in the world does the compiler generate partition entries for variables that aren't even mentioned in the source file? > [...] >> > Sorry for shouting, but I'm getting really sick of your unjustified >> > attacks. If your variables have visibility as in Fortran, it *works*.[...] WHAT visibility "as in Fortran?" In Fortran, only locally declared objects are visible. If you want to access a global variable in Fortran, you must locally declare it and locally import it (with a COMMON statement) in each procedure that uses it. To get the same visibility rules in C, you have to compile the C code in a separate file for each procedure. This is _exactly_ the form of the example I've given in this thread. In Fortran, the call to sub2() in the example would be illegal. The compiler would generate the FAST (alias free) code for all procedures. In C, the call to sub2() is legal. Since the codes in sub2() and sub3() are symmetric, the compiler clearly must make the _same_ decision about which aliasing status to pick on _both_ procedures. Since the only safe pick is the SLOW (aliasing present) versions, you will pick the wrong one for sub3(). Either that, or you're going to choose an unsafe version of sub2(). The only way to avoid this difficulty is to propagate the aliasing constraints through the call tree. You said above (and I repeat here): > [...] The partitions for > sub1() include a and b, as do the partitions for sub2() and sub3(). And indeed, for your scheme to work, the partitions for sub1() _should_ include a and b. But, your method (as stated) will _not_ include them. Those two variables are _never_ mentioned in the file containing sub1(). J. Giles