|Fortran to C/C++ translation: a running example. firstname.lastname@example.org (Rock Brentwood) (2022-05-16)|
|Re: Fortran to C/C++ translation: a running example. email@example.com (Thomas Koenig) (2022-05-17)|
|Re: Fortran to C/C++ translation: a running example. firstname.lastname@example.org (Lydia Marie Williamson) (2022-05-20)|
|Re: Fortran to C/C++ translation: a running example. email@example.com (gah4) (2022-05-21)|
|Re: Fortran to C/C++ translation: a running example. firstname.lastname@example.org (Thomas Koenig) (2022-05-21)|
|From:||Thomas Koenig <email@example.com>|
|Date:||Sat, 21 May 2022 17:24:37 -0000 (UTC)|
|Injection-Info:||gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="61499"; mail-complaints-to="firstname.lastname@example.org"|
|Posted-Date:||21 May 2022 13:26:54 EDT|
Lydia Marie Williamson <email@example.com> schrieb:
> On Monday, May 16, 2022 at 2:53:09 PM UTC-5, Rock Brentwood wrote:
>> Another key issue the aliasing that goes on with "equivalence" constructs.
>> There is no good uniform translation for this into C ... it actually better
>> fits C++, where you have reference types available. There's really no good
>> reason why those have been left out of C, when other things which appeared
>> first in C++, like "const", "bool" or function prototypes, found their way
>> into C.
>> However, a substantial chunk of use-cases for equivalence constructs can be
>> carved out as "enum" types, so there was a strength reduction step for this,
> This is not exactly correct. It's "common blocks" that were handled in this way.
> In the Fortran source of Zork/dungeon, the "equivalence" statements and
> "common blocks" were used together, so it's easy to get the issue confused. I
> don't know if their being used together is something that always happened in
> Fortran, or if it was just particular to this program.
Fortran has the concept of storage association - under certain
circumstances, the ordering of variables is prescribed by the
COMMON blocks are one example of this. Taking an example from the
original Fortran source code:
COMMON /SYNTAX/ VFLAG,DOBJ,DFL1,DFL2,DFW1,DFW2,
This declares a common block /SYNTAX/ with 11 named variables
(all of them integers due to an IMPLICIT INTEGER (A-Z) earlier in
all files), which have to be contiguous in memory.
The next line
declares an integer array with 11 elements.
Finally, the statement
EQUIVALENCE (VFLAG, SYN)
tells the compiler that the address of the (first element of) SYN
and VFLAG are the same.
So, you can now use SYN(1) to refer to VFLAG, SYN(2) to DOBJ and so on.
Why is this done? I see only one use case, in np3.for
DO 10 I=1,11
C !CLEAR SYNTAX.
simply to create a shortcut for clearing the syntax.
This is a benign (and standard-conforming) way of using COMMON
and EQUIVALENCE. Equivalent C code might create a 'struct syntax'
and clear it with a memset, or have 11 individual variables and
zero them individually.
Return to the
Search the comp.compilers archives again.