home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20271 comp.lang.fortran:5204
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!darwin.sura.net!bogus.sura.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!nntp-server.caltech.edu!sampson!shepard
- From: shepard@sampson.ccsf.caltech.edu (Ron Shepard)
- Newsgroups: comp.lang.c,comp.lang.fortran
- Subject: Re: calling a Fortran subroutine from a C program
- Date: 26 Jan 1993 21:11:06 GMT
- Organization: California Institute of Technology, Pasadena
- Lines: 49
- Distribution: na
- Message-ID: <1k49dbINNeij@gap.caltech.edu>
- References: <1993Jan23.152153.7178@biome.bio.ns.ca> <ig25.728061129@fg30> <1993Jan26.160622.24483@sol.ctr.columbia.edu>
- NNTP-Posting-Host: sampson.ccsf.caltech.edu
-
- In article <1993Jan26.160622.24483@sol.ctr.columbia.edu> shenkin@still3.chem.columbia.edu (Peter Shenkin) writes:
- >In article <ig25.728061129@fg30> ig25@fg30.rz.uni-karlsruhe.de (Thomas Koenig) writes:
- >>An implementation might very well choose to start every character
- >>variable on a word boundary, for speed reasons.
- >>
- >> CHARACTER*1 STRING(100)
- >>
- >>would then appear to C to be an array of ints, instead of chars.
- >
- >I think Cray in fact does this, while placing CHARACTER*1 scalars
- >on byte boundaries.
- >
- > -P.
-
- Fortran requires some storage relations to hold between character
- scalars and arrays. Most fortran programmers know this, but since
- this is being posted in comp.lang.c, this may not be known to
- everyone reading this thread. In particular
-
- character*1 array(100)
- character*100 scalar
- equivalence (array, scalar)
-
- requires that array(i) and scalar(i:i) refer to the same character
- storage location. In argument passing, the "implied" length passed
- with "array" is 1, whereas the length passed with "scalar" is 100.
-
- The "array of ints" comment above is incorrect because of this
- storage location requirement. It is true that the initial
- character of fortran variables and arrays is sometimes aligned to
- some data boundary, but this alignment must be consistent with any
- equivalence statements, and with any implied equivalences of
- scalars and arrays through subroutine argument association. The
- Cray does not have "byte boundaries" since it is (64-bit) word
- addressable. Character pointers on a Cray have two pieces, a word
- pointer and a character offset within the word. The Cray C
- compiler/preprocessor has builtin macros for extracting this
- information from the structure used by fortran when passing
- character variables as arguments.
-
- It is sometimes simply a matter of taste as to whether characters
- are referenced as array elements, array(i), or as substring
- expressions, scalar(i:i). Since Fortran 77 supports common character
- operations (substring indexing, substring matching, substring
- concatenation, etc.), character*1 arrays are not used in the same
- way, or as often, as they are in C.
-
- -Ron Shepard
- shepard@tcg.anl.gov
-