Date: Sat, 21 Jun 1997 15:27:31 -0700 (PDT) Message-Id: <199706212227.PAA05972@geocities.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: djgpp AT delorie DOT com From: Guilherme Silveira Subject: RE: Callbacks Precedence: bulk Please, can you give me an example with a function that returns an int and got 2 parameters, one array of chars (70 chars) and one integer? At 11:26 18/06/1997 +0100, you wrote: >> >>Goretec3 (goretec3 AT aol DOT com) writes: >>> What are interrupt calbacks. I saw one when I was looking through some >>> allegro code. >> >>Unless you are a wizard or some kind of guru... you don't want to know. ;-) > >Sorry, but if thats your attitude then you are missing out on a >particularly effective method of >calling routines... > >In C it is possible to have pointers not only to data, but to functions >as well, these are the pointers that are passed to interrupt handling >routines in Allegro and other such API's. It works that when an >interrupt is processed, the function, which you registered the pointer >for is called. > >You do not have to have these only for Interrupts, they are particularly >effective for state transition when you want to program objectively in >C.... > >/* StateTransitions.c */ >#include >#include > >/* were gonna model a fish object */ >typedef int ( *FISH_STATE )( ); > >/* now we define the possible states */ >int fishSwimming(); >int fishEating(); >int fishSleeping(); >int fishProCreating(); > >FISH_STATE pfnFishState; > >/* the main function */ >int main( void ) >{ > int i; > > pfnFishState = fishSwimming; > > /* duty cycle */ > for( i=0; i<999; i++ ) > { > /* call the function of the current state */ > pfnFishState(); > } >} > >int fishSwimming() >{ > printf( "swimming\n" ); > /* is food near */ > if( food_is_near ) > { > pfnFishState = fishEating; > } > > if( time_for_bed ) > { > pfnFishState = fishSleeping; > } > > /* ..... and so on ..... */ >} > >Does this help at all? > > >Rob Humphris > >> > --------------------------------------------------------------- Guilherme Silveira - Sao Paulo - Brasil carlos AT usway DOT com - thedarkage AT mail DOT geocities DOT com http://www.geocities.com/SiliconValley/Way/5441/ 18/09/1981 - Until Today...