Mail Archives: djgpp/1997/12/29/22:49:19
Gary wrote:
>
> Hello all,I am a learner of C and are somewhat puzzled by some code
> I've come across in Allegro,namely in allegro.h where it states as
> follows #define END_OF_FUNCTION(x) x##_end(){}
<SNIP>
> I know that this query is possibly more to to do with another ng,but
> since its allegros code I have posted it here,any help to enlighten me
> to how this works or what it means would be much appreciated.
it is quite topical actually. since djgpp uses virtual memory, code that
can be called in an interrupt context needs to be locked so that it does
not get swapped out to disk. for that, one needs to know where the
function begins and ends. the macro above is a commonly used trick
whereby a dummy function immediately following the function that needs
to be locked is used as a marker for the end of the area that needs to
be locked.
given a function func
END_OF_FUNCTION(func)
expands to
func##_end() {}
which, assuming consecutive function bodies are laid out consecutively,
can be used (since function names can be regarded as pointers) as
func##_end - func to calculate the size of the region to lock.
one question: would it be better to explicitly declare the argument and
return types for the dummy function as void instead of relying on
default behavior? probably doesn't make a difference, but ...
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -