Message-ID: From: Robert Humphris To: "'djgpp AT delorie DOT com'" , "'ao950 AT FreeNet DOT Carleton DOT CA'" Subject: RE: Callbacks Date: Wed, 18 Jun 1997 11:26:00 +0100 Encoding: 74 TEXT Precedence: bulk > >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 >