CompuServe Thread

#Simple C question

2 messages in this thread
#32515From: Doug WalkerFeb 25, 1993 4:46 PM
A #pragma is a way of specifying compiler-specific information. In this case, the SAS/C compiler is using information specified in #pragma statements to figure out how to call system routines. If you call a normal C function, the parameters are pushed onto the stack or loaded into registers, then you jump to the function. The problem is that this doesn't work with AmigaDOS libraries, because your program doesn't know at link time where in memory the library is going to be loaded when the program is run. The solution to this is to get the library base, and jump to a location relative to it. Now C isn't by nature set up to do this. It wants to push the parameters on the stack and be done with it. So when the Amiga came out, Commodore provided little assembly-language stub functions that you linked into your program. They pretended to be the various Amiga library functions (like OpenWindow, OpenScreen, etc.) but all they really did was 1) pop the parameters into registers, 2) load up the library base into register A6, and 3) jump to the library routine relative to A6. There's really no reason the compiler can't generate code to do this itself, however – IF it knows enough information about the funtion you are calling. Thus, the #pragma statements. The #pragmas tell the compiler all about the function you are calling – what library base to load, which registers the paramters go into, etc. If you don't #include them, you get the old method – the assembly stubs are linked in from amiga.lib. If you do, however, you get more efficient code since there is one fewer jump and probably less pushing and popping the stack. This is described in the Library Reference Manual, I believe. That manual also describes the somewhat cryptic format of the #pragmas. –Doug
#32591From: Robert PigfordFeb 28, 1993 4:27 PM
Doug – Thanks for the lesson – I'll need to reread it a few times to digest it, but I'll understand all this yet. /7 //\ob …on Amiga via Autopilot from Northeastern PA…