C (149/304)

From:Allan Odgaard
Date:16 Aug 2000 at 17:18:35
Subject:Re: Just a wee question

On 16-Aug-00, Charles Barr wrote:

> I just have a we question that been enoying me for some time.
> what does __saveds and __asm actually mean?

A compiler may keep register A4 pointing to the start of all global
variables, and then access these as an offset to A4 (because this is a
little faster), but that also means that A4 must always point to the
data segment, so if you have a function which is called from outside
your code (like a hook) you put the save-data-segment keyword in front
of it, to indicate that the compiler should load register A4 before
making access to global variables (as it won't be pre-set). A program
coded 'properly' have very few accesses to global variables, so here it
may actually be better not to compile/link the program to make use of a
data segment register, due to the occasional loads, and the occupied
register -- but I haven't tested it (I always link my code without a DS
register, as it saves me for the trouble of thinking of __saveds).

I have no idea about 'asm' -- it's not supported by StormC. The name
indicates that it's to indicate that the function may e.g. be called
from assembly, so the compiler should do any special tricks, which
require the caller to be aware of them, but I'm only guessing... I'm
looking forward to the real explanation :-)

Regards Allan