Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!weyrich!orville From: orville@weyrich.UUCP (Orville R. Weyrich) Newsgroups: comp.lang.fortran Subject: Re: Pseudo-FORTRAN -- f2c for the Macintosh Message-ID: <1991Jun1.171914.802@weyrich.UUCP> Date: 1 Jun 91 17:19:14 GMT References: <1991May30.040829.8696@eplrx7.uucp> <1017@DIALix.oz.au> Reply-To: orville@weyrich.UUCP (Orville R. Weyrich) Organization: Weyrich Computer Consulting Lines: 64 In article <1017@DIALix.oz.au> dent@DIALix.oz.au (Andrew Dent) writes: > >I'd be very interested to hear if f2c generates successful code for the >Mac as I've spent most of the past 3 months writing a converter from FORTRAN to >THINK Pascal. The biggest problem I encountered is the way the Mac stores >integers, which causes major problems with arrays of different cell sizes >being EQUIVALENCED. > >eg: INTEGER*2 little(2) > INTEGER*4 big > EQUIVALENCE (little,big) > little(1) = 10 > little(2) = 99 > >dent@DIALix.oz.au (international) Of course you are having trouble translating. Your source code is NOT FORTRAN, at least in the sense of conforming to the FORTRAN-66 and FORTRAN-77 standards. [I don't have my copy of the standard handy, so I can't quote verbatim, but the general idea is that when equivalencing dissimilar types, it can be done only to save storage by re-using the same statically allocated region in non-interacting parts of the program. Creative use of EQUIVALENCE to do bit-twiddling is not allowed by the standard. In your example, when array "little" becomes defined, array "big" becomes undefined, and vice-versa]. This is not an issue pertaining to translating FORTRAN to Pascal. This is an issue pertainig to porting non-standard FORTRAN code from one hardware platform to another. That is, you should have no problem translating a program that works in Mac FORTRAN to Mac Pascal. The problem you are experiencing is EXACTLY the reason why the FORTRAN standard does not allow using EQUIVALENCE in the way your source code does. This leads to the $500,000 question: do algorithms exist which can do something intelligent with such uses of EQUIVALENCE? YES, I WOULD BE VERY INTERESTED IN THE ANSWER TO THE ABOVE QUESTION. Failing to get an acceptable answer to that question, my best advice is to do one of the following: 1) Flag that portion of the translation as needing manual attention. or 2) Modify the original source code to not mis-use EQUIVALENCE before attempting the translation. Neither of these are particularly desirable :-(. By the way, you are not alone. There is commercial software that is known for its portability (the IMSL mathematical library) that [at least used to] play such standard-breaking tricks with equivalence in order to implement extended precision addition and multiplication (VXPADD, VXPMUL as I recall). They hid the standard violation inside small subroutines, and had separate versions of the subroutines for different hardware platforms. -------------------------------------- ****************************** Orville R. Weyrich, Jr., Ph.D. Certified Systems Professional Internet: orville%weyrich@uunet.uu.net Weyrich Computer Consulting Voice: (602) 391-0821 POB 5782, Scottsdale, AZ 85261 Fax: (602) 391-0023 (Yes! I'm available) -------------------------------------- ******************************