🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #7085

Re: Lattice C : pragma? Whats all this then?

#7085
From: Doug Walker
Date: Wed, 28 Nov 1990 20:23
61 lines
3547 bytes
In article <1990Nov10.001056.9736@canterbury.ac.nz> cctr120@canterbury.ac.nz (Brendon Wyber, C.S.C.) writes:
>Hi,
>
>I am using Lattice C v5.05 and have been using the ProtoType files. I've
>noticed that the #pragma calls for INCLUDE:proto/cstrings.h refer to
>a variable CStringBase. 

cstrings.h is obsolete.  That library no longer exists.  You can delete
all references to it.

>
>This was a real nuisance because when linking it kept wanting me to define it 
>until I figures out I needed to to a #define NO_PRAMGAS. However what is 
>bothering me is exactly what Library is that calling to?

Defining NO_PRAGMAS is bad - it means you won't call any other Amiga
libraries through the pragmas either.

>
>Also what difference do Pramgas make? Is it done so that I can link to less
>things? IE use my own c.o and miss out amiga.lib and lc.lib, (all in the
>search for smaller code :-) ).

This is a fairly often-asked question, so here's my canned spiel
on pragmas:

Amiga shared libraries (like dos.library, exec.library, intuition.library)
all have lists of functions that are accessible via that library's base
pointer (DOSBase, ExecBase, IntuitionBase, etc.)  The #pragma statement
is used to access these functions.  Basically, the library base points to
a section of memory with a list of assember JMP instructions right before
it.  To call routine FOO in that library, your code does a JSR (jump to
subroutine) to some offset relative to the library base, the JMP (jump)
jumps you into the ROM or RAM or whereever the library routine is, the 
routine executes, and it does an RTS to return to your code.
 
The problem with this is that the library routines take their parameters in
specific registers.  Normal C calling conventions call for pushing the
parameters onto the stack.  The solution back in the early days was to
provide small 'stub' routines for each library routine that your C program
would call.  The stub routine would pop the parameters off the stack into
the proper registers, load up the proper library base into register A5,
and branch to the right place.  These routines still exist in amiga.lib.
 
The #pragmas tell the compiler everything it needs to know to eliminate
these stub routines and call the library function directly.  It gives
the library base name (like IntuitionBase), the offset of the JMP
instruction for the routine, and a 'magic' value that tells it what
registers each parameter goes in.  When the compiler sees a call to, say,
OpenScreen, it loads the parameters in the proper registers, loads 
IntuitionBase into A5, and JSR's to the proper offset relative to A5.
This is quite a bit less overhead than the amiga.lib method.
 


  *****                              v Yes, I mean Distiller, not Distillery!
=*|_o_o|\\=====Doug Walker, Software Distiller====== BBS: (919)460-7430 =
 *|. o.| ||                                          1200/2400/9600 Dual
  | o  |//     For all you do, this bug's for you!
  ====== 
usenet: ...mcnc!rti!sas!walker   plink: dwalker  bix: djwalker 
Technical Details
Message-ID: <1990Nov28.202329.3516@unx.sas.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!emory!gatech!mcnc!rti!mozart!walker
References: <1990Nov10.001056.9736@canterbury.ac.nz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!emory!gatech!mcnc!rti!mozart!walker
From: walker@unx.sas.com (Doug Walker)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Lattice C : pragma? Whats all this then?
Message-ID: <1990Nov28.202329.3516@unx.sas.com>
Date: 28 Nov 90 20:23:29 GMT
References: <1990Nov10.001056.9736@canterbury.ac.nz>
Organization: SAS Institute Inc.
Lines: 61