From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public X-Google-Thread: 1164f8,45b50f14dadfce5b X-Google-Attributes: gid1164f8,public From: Richard Black Subject: Re: Final kick at the "Merced Guessing Game" Date: 1997/10/14 Message-ID: #1/1 X-Deja-AN: 280694530 References: <61g30t$o2n@news-rocq.inria.fr> <61uoiu$19e$1@goanna.cs.rmit.edu.au> <61vbv8$nct@sis.cambridge.arm.com> Organization: SRG, Computing Science, University of Glasgow Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec michael.williams@arm-sponge.com (Michael Williams) writes: > > In article <61uoiu$19e$1@goanna.cs.rmit.edu.au>, > Richard A. O'Keefe wrote: > >A Fortran compiler is allowed to say "hey, I know the result of 0*F() > >without calling F, so I won't call F". A C compiler is not. > >Sun's f77 compiler actually does this. I put that example in a file > >called 'foo.f' and did f77 -O5 foo.f; a.out The program compiled, > >linked, ran, and printed 0. The C version, however, doesn't link, > >because it must call f. > > Actually, gcc probably wouldn't link even if it had optimised out the > call to f(), e.g.: > > if (0) f(); > > still generates an undefined reference to 'f' in the object file (even > though the call to 'f' is optimised out, in this case). > F > > Mike. (Learning even more about Fortran every day.) But if gcc knows the same amount of information as Fortran (i.e. that f() is side-effect-free) it can also make the same optimisation. viz: extern int f(int a) __attribute__ ((const)); int b(int a) { return 0 * f(a); } becomes (since you are at ARM): @ Generated by gcc 2.7.2 for ARM/(generic) rfp .req r9 sl .req r10 fp .req r11 ip .req r12 sp .req r13 lr .req r14 pc .req r15 gcc2_compiled.: ___gnu_compiled_c: .text .align 0 .global _b _b: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 1, current_function_anonymous_args = 0 mov ip, sp stmfd sp!, {fp, ip, lr, pc} mov r0, #0 sub fp, ip, #4 ldmea fp, {fp, sp, pc} At its core this whole discussion is not really a FORTRAN versus C issue. Its a question of "How do we come up with a language that allows us to represent what is really going on in such a way that it is easy for the programmer to specify (correctly!) and possible for the compiler to make effective use of it." Fortran "solves" this problem by having a restricted type system which makes it inappropriate for some problems (e.g. writing operating systems and device drivers). C's type system is simply pathetic, C++ is worse, and Java's is only marginally better than C's. >From the other point of view the functional programming people understand type systems properly but have yet (in my experience) to provide a language which allows nasty things like device drivers to be written. [ Consider 'void reschedule(void)' Fortran might optimise such a thing out, which might be very bad for your operating system.... ] Oh, and this language has to be both non-proprietary and have huge industry support. It may well be that we have to go from here to there in steps, and that Java is the first such. -- ----------------------------------------------+------------------------ Dr. R.J. Black, University Lecturer, | Phone: +44 141 330 6039 University of Glasgow, Computing Science Dept.| Fax: +44 141 330 4913 17 Lillybank Gdns., Glasgow G12 8RZ, U.K. | Mail: rjb@dcs.gla.ac.uk