home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20271 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  2.8 KB

  1. Xref: sparky comp.lang.c:20271 comp.lang.fortran:5204
  2. 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
  3. From: shepard@sampson.ccsf.caltech.edu (Ron Shepard)
  4. Newsgroups: comp.lang.c,comp.lang.fortran
  5. Subject: Re: calling a Fortran subroutine from a C program
  6. Date: 26 Jan 1993 21:11:06 GMT
  7. Organization: California Institute of Technology, Pasadena
  8. Lines: 49
  9. Distribution: na
  10. Message-ID: <1k49dbINNeij@gap.caltech.edu>
  11. References: <1993Jan23.152153.7178@biome.bio.ns.ca> <ig25.728061129@fg30> <1993Jan26.160622.24483@sol.ctr.columbia.edu>
  12. NNTP-Posting-Host: sampson.ccsf.caltech.edu
  13.  
  14. In article <1993Jan26.160622.24483@sol.ctr.columbia.edu> shenkin@still3.chem.columbia.edu (Peter Shenkin) writes:
  15. >In article <ig25.728061129@fg30> ig25@fg30.rz.uni-karlsruhe.de (Thomas Koenig) writes:
  16. >>An implementation might very well choose to start every character
  17. >>variable on a word boundary, for speed reasons.
  18. >>
  19. >>      CHARACTER*1 STRING(100)
  20. >>
  21. >>would then appear to C to be an array of ints, instead of chars.
  22. >
  23. >I think Cray in fact does this, while placing CHARACTER*1 scalars
  24. >on byte boundaries.
  25. >
  26. >    -P.
  27.  
  28. Fortran requires some storage relations to hold between character
  29. scalars and arrays.  Most fortran programmers know this, but since
  30. this is being posted in comp.lang.c, this may not be known to
  31. everyone reading this thread.  In particular
  32.  
  33.     character*1   array(100)
  34.     character*100 scalar
  35.     equivalence  (array, scalar)
  36.  
  37. requires that array(i) and scalar(i:i) refer to the same character
  38. storage location.  In argument passing, the "implied" length passed
  39. with "array" is 1, whereas the length passed with "scalar" is 100.
  40.  
  41. The "array of ints" comment above is incorrect because of this
  42. storage location requirement.  It is true that the initial
  43. character of fortran variables and arrays is sometimes aligned to
  44. some data boundary, but this alignment must be consistent with any
  45. equivalence statements, and with any implied equivalences of
  46. scalars and arrays through subroutine argument association.  The
  47. Cray does not have "byte boundaries" since it is (64-bit) word
  48. addressable.  Character pointers on a Cray have two pieces, a word
  49. pointer and a character offset within the word.  The Cray C
  50. compiler/preprocessor has builtin macros for extracting this
  51. information from the structure used by fortran when passing
  52. character variables as arguments.
  53.  
  54. It is sometimes simply a matter of taste as to whether characters
  55. are referenced as array elements, array(i), or as substring
  56. expressions, scalar(i:i).  Since Fortran 77 supports common character
  57. operations (substring indexing, substring matching, substring
  58. concatenation, etc.), character*1 arrays are not used in the same
  59. way, or as often, as they are in C.
  60.  
  61. -Ron Shepard
  62. shepard@tcg.anl.gov
  63.