delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/29/22:49:19

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Puzzled:Allegro Code
Date: Mon, 29 Dec 1997 22:37:20 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 41
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <34A86C70.82B0D50@cornell.edu>
References: <683mjc$gj8$1 AT nclient3-gui DOT server DOT virgin DOT net> <438_9712301100 AT softtech DOT st DOT net DOT au>
NNTP-Posting-Host: cu-dialup-0041.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019