home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / ada / 3289 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.2 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!wupost!uwm.edu!linac!att!ucbvax!efftoo.boeing.com!crispen
  2. From: crispen@efftoo.boeing.com (crispen)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: Calling Ada from a non-Ada language
  5. Message-ID: <9211161340.AA29041@efftoo.boeing.com>
  6. Date: 16 Nov 92 13:40:27 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: world
  9. Organization: The Internet
  10. Lines: 37
  11.  
  12. dale.ksc.nasa.gov!rsimonia@ames.arc.nasa.gov  (Rick Simonian)
  13. asks about calling Ada from (e.g.) C.
  14.  
  15. We have done this, especially where early Ada bindings were absent
  16. or broken (e.g., for DevGuide or SunView on the Sun), recognizing that we
  17. would probably dump this code as soon as we got good bindings.
  18.  
  19. You *have* to have an Ada main(), so far as I know.  The reason is
  20. that Ada does elaboration (sure of this) and task spawning (I think
  21. this is what the code I've seen does) before it hits the first
  22. line of main().  Obviously, C has never heard of either of these
  23. activities as requirements before executing main().
  24.  
  25. We always had to fool around a bit with arguments before we got
  26. things to work.  C calls by value and Ada calls by reference -- sometimes.
  27. When?  You'll find out!  C strings don't look like Ada strings.  And Ada and
  28. C structs sometimes need to be tweaked (the last two are true going either
  29. way, of course).  For example, the following:
  30.  
  31.     struct foo {
  32.         short    a;
  33.         int    b;
  34.         };
  35.  
  36. is 8 bytes long on the SPARC (have to look at ANSI C to see if this
  37. is required or permitted).  Ada may have its own ideas about sizes
  38. and alignments unless you give it a rep spec.  Don't rely on an Ada
  39. record always matching a C struct.
  40.  
  41. Anyway, unless you're the only person in the world who wants to do
  42. a particular job, you'll usually find Ada bindings that will let you
  43. throw out your C-to-Ada code.  Eventually.
  44. +-------------------------------+--------------------------------------+
  45. | Bob Crispen                   |  Who will babysit the babysitters?   |
  46. | crispen@foxy.boeing.com       +--------------------------------------+
  47. | (205) 461-3296                |Opinions expressed here are mine alone|
  48. +-------------------------------+--------------------------------------+
  49.