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

  1. Xref: sparky comp.lang.c:20092 comp.lang.fortran:5136
  2. Newsgroups: comp.lang.c,comp.lang.fortran
  3. Path: sparky!uunet!cs.utexas.edu!hermes.chpc.utexas.edu!michael
  4. From: michael@chpc.utexas.edu (Michael Lemke)
  5. Subject: Re: calling a Fortran subroutine from a C program
  6. Message-ID: <1993Jan22.233618.17814@chpc.utexas.edu>
  7. Organization: The University of Texas System - CHPC
  8. References: <1993Jan22.190624.23084@chpc.utexas.edu> <1993Jan22.200839.8352@sol.ctr.columbia.edu>
  9. Date: Fri, 22 Jan 93 23:36:18 GMT
  10. Lines: 63
  11.  
  12. In article <1993Jan22.200839.8352@sol.ctr.columbia.edu> bobp@msi.com (Bob Pitha) writes:
  13. >Michael Lemke (michael@chpc.utexas.edu) wrote:
  14. >: In article <1993Jan22.130743.27130@sol.ctr.columbia.edu> bobp@msi.com (Bob Pitha) writes:
  15. >   (edited a bit for brevity's sake)
  16. >: >
  17. >: >4) Character arrays: For each character array in the argument list, there
  18. >:               ^^^^^^
  19. >
  20. >: You are not talking about character arrays at all in your post.  A 
  21. >: character array is something you declare as
  22. >
  23. >:     character*(*) string(10)
  24. >
  25. >: which is an array of strings.  You talked just about plain character
  26. >: strings.  Keep the terms clear.  Passing of character arrays is a bit
  27. >: harder than what you described I believe (I might be wrong) but I don't
  28. >: have my Sun manual handy to point out the differences.  Someone else
  29. >: might.  But as you have suggested (which I deleted for brevity) reading
  30. >: the Sun Fortran manual is worth doing.  It deals with all these issues.
  31. >
  32. >  This is really just an issue of semantics, but you're right that I wasn't
  33.                           ^^^^^^^^^^^^^^^^^^
  34.  
  35. Not quite.  To make it really clear:  The difference is
  36.  
  37.     CHARACTER*100 STRING
  38.  
  39. or
  40.  
  41.     CHARACTER*1 STRING(100)
  42.  
  43. which are very different data structures.   The latter is an array, the
  44. first is a single variable.  I don't care how C chews its memory, it can
  45. hardly distinguish these two cases.  The last is pretty close in
  46. functionality to C's concept (except for having a length stored
  47. somewhere) as you'd need something like strcpy to copy data.
  48.  
  49. >very clear.  I was thinking in terms of an "array of type char" in C, so
  50. >I just wrote what I was thinking.  As you point out, to a person who only
  51. >knows Fortran the phrase "character array" may by misleading.  Unfortunately,
  52. >this is an area where the concepts don't map well between the two worlds,
  53. >since c doesn't have an official "string" type; a string is just a null-
  54. >terminated array of characters.
  55. >
  56. >  Passing "arrays of strings" (is that clear enough?) is perhaps a little
  57. >bit harder, but not a whole lot.  I didn't touch on null-termination and
  58. >blank-filling in my previous post because I didn't know whether the
  59. >original questioner cared and it would have taken lots more space.  I
  60. >stuck to the simple case of passing an array of characters to the Fortran
  61. >routine.  If the Fortran routine were going to try to pass a string back
  62. >to C, or if an array of strings were being passed, you have to deal with
  63. >these issues.
  64. >
  65. >-----------------------------------------------------------------------
  66. >Bob Pitha                      Molecular Simulations Inc.
  67. >bobp@msi.com                   16 New England Executive Park
  68. >(617) 229-9800 x242            Burlington, MA 01803-5297
  69.  
  70.  
  71. -- 
  72. Michael Lemke
  73. Astronomy, UT Austin, Texas
  74. (michael@io.as.utexas.edu or UTSPAN::UTADNX::IO::MICHAEL [SPAN])
  75.