Xref: utzoo comp.lang.c:17641 comp.lang.fortran:1937 Newsgroups: comp.lang.c,comp.lang.fortran Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: fortran to C converter Message-ID: <1989Apr14.161147.28053@utzoo.uucp> Organization: U of Toronto Zoology References: <1989Apr13.173331.2116@utzoo.uucp> <12000@lanl.gov> Date: Fri, 14 Apr 89 16:11:47 GMT In article <12000@lanl.gov> jlg@lanl.gov (Jim Giles) writes: >... In any case, the mechanism you describe (and any C++ >mechanism) would require 7 different definitions for each operator: >COMPLEX*INT, COMPLEX*FLOAT, COMPLEX*DOUBLE, COMPLEX*COMPLEX, INT*COMPLEX, >FLOAT*COMPLEX, DOUBLE*COMPLEX. Or did you think that an implementation >that _didn't_ support mixed mode operations was satisfactory? ... Um, it may not have come to your attention that C++ will do conversions for you (given definition of suitable conversion operators). See pages 173-177 in Stroustrup's book; you have in fact hit on *precisely* the example he uses to explain why automatic application of user-defined conversions is a good thing. If that is not satisfactory, i.e. if you really do want all those operations to be different, you will of course need to specify them all no matter what you do. > COMPLEX A,B,C > REAL X > ... > B=X > A=B*C > >All the Fortrans I've ever used would recognize an optimization that >I've not seen _any_ C++ compiler recognize: The multiply need only >do 2 FLOAT multiplies, not 4 multiplies and 2 adds. The C++ code will >blindly follow the definition of the operator (COMPLEX*COMPLEX) and >will not notice that the imaginary part of B is guaranteed to be zero. >Even if you solve the 'inlining' problem I mentioned in my last article, >these problems of mixed mode and optimization make the C++ implementation >less desireable. Given in-header definitions of the operators, there is no reason why a C++ optimizing compiler can't do this. Existing C++ compilers, by and large, are not heavy optimizers; the language is too young for that yet. They will come. -- Welcome to Mars! Your | Henry Spencer at U of Toronto Zoology passport and visa, comrade? | uunet!attcan!utzoo!henry henry@zoo.toronto.edu