home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17490 < prev    next >
Encoding:
Internet Message Format  |  1992-12-18  |  3.6 KB

  1. Path: sparky!uunet!news.tek.com!tekig7!tekig1!brianr
  2. From: brianr@tekig1.PEN.TEK.COM (Brian E Rhodefer)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Does opening libraries require a fixed varname?
  5. Summary: Pretty much.
  6. Message-ID: <8011@tekig7.PEN.TEK.COM>
  7. Date: 17 Dec 92 23:40:38 GMT
  8. References: <BzDnFz.FM5@usenet.ucs.indiana.edu>
  9. Sender: news@tekig7.PEN.TEK.COM
  10. Reply-To: brianr@tekig1.pen.tek.com
  11. Followup-To: poster
  12. Distribution: na
  13. Organization: Tektronix, Inc., Beaverton,  OR.
  14. Lines: 61
  15.  
  16. In article <BzDnFz.FM5@usenet.ucs.indiana.edu> shulick@navajo.ucs.indiana.edu writes:
  17. >
  18. >If I wanted, for instance, to open intuition.library, does the line
  19. >*HAVE* to be:
  20. >
  21. >IntuitionBase = OpenLibr.......
  22. >
  23. >Can it be something like "IBase = OpenLibrary(.." or "blech = Open..."
  24. >In other words, does it matter what you call the variable?
  25. >GadToolsBase, ExecBase, GfxBase, etc.
  26. >
  27.  
  28. You're well advised to stick to the standard names for the library base
  29. variables.  Somehow or other, when you try to *use* an Amiga library
  30. function with a statement like,
  31.  
  32.  "... myWindow = OpenWindow(blah, blah);",
  33.  
  34. your compiler has to arrange to call the correct offset in the correct
  35. library, and it's pretty much got to be able to make an assumption about
  36. where to find the library base (seeing as how the library base doesn't
  37. appear in the argument list of the call).  The assumption it makes,
  38. one way or another, is that the library base is cached in the "standard"
  39. variable.
  40.  
  41. In the early days, my Manx Aztec C ( and I assume Lattice, too)
  42. compiler didn't call the Amiga library directly, but would instead
  43. call a "glue routine" which would copy the arguments off the stack
  44. (i.e., the library routines appeared to be "standard" C subroutines;
  45. therefore, their arguments got shoved on the stack) and into the registers
  46. that the Amiga library package expected, and then called the correct
  47. offset from the library base.  These glue routines needed to use the
  48. correct Library base address, of course, and the way that they GOT the
  49. base address was to declare the base address to be an extern Library *,
  50. and let the linker establish the connection to the library that your
  51. code opened.  Ergo, if you didn't provide a global variable of the exactly
  52. correct name, you'd get an "Undefined symbol" error at link-time.
  53.  
  54. I don't remember which compiler "invented" the feature first, but both
  55. of them now can generate direct calls on Amiga library functions without
  56. going through a glue routine.  This trick still depends on the compiler's
  57. assumption about where to find the library base address being justified
  58. by your choice of variable name, however.  I only recently switched my
  59. allegiance from Manx to SAS, and haven't got much experience with SAS,
  60. but I recall that the Manx V5.whatever compilers allowed you to do a library
  61. function call with an explicit "libCall(libraryBase,LibraryOffset,arg...)"
  62. statement.  A lot more clutter, though, than just doing
  63. "LibraryFunction(arg...);".
  64.  
  65. The SAS 6.0 stuff is REALLY slick, though, in that it will automatically
  66. handle the opening and closing of libraries FOR YOU!!!  Apparently, when
  67. the standard c linker-libraries (as distinct from Exec libraries) are
  68. scanned, if the "standard" library base variable names (e.g., IntuitionBase)
  69. are found to be unresolved symbols in your object module, the modules pulled
  70. from the linker library that resolve them also supply OpenLibrary() and
  71. CloseLibrary() initialization/finalization subroutines for them that get
  72. automagically linked into the startup/termination code (the stuff that calls
  73. your "main()").  But, again, in order for this magic to work, you have to
  74. use the "standard" names for things.
  75.  
  76. Brian Rhodefer
  77.