home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!mama!greyham
- From: greyham@research.canon.oz.au (Graham Stoney)
- Subject: Re: How to have a member function as an ISR
- Message-ID: <Brv9Ku.25A@research.canon.oz.au>
- Sender: news@research.canon.oz.au
- Organization: Canon Information Systems Research Australia
- References: <emm.711411003@daneel.rdt.monash.edu.au> <1992Jul20.121028.16381@pegasus.com>
- Date: Fri, 24 Jul 1992 00:05:17 GMT
- Lines: 29
-
- sean@pegasus.com (Sean Donovan) writes:
- >In article <emm.711411003@daneel.rdt.monash.edu.au> emm@daneel.rdt.monash.edu.au (Wendigo) writes:
- >>Does anybody know how to use a member function of a class as an
- >>Interrupt Service Routine using Borlanc C/C++ 3.0??
-
- >First declare it as type interrupt.
-
- >Second, write the equivalent of dos_setvec() for your class acception
- >a pointer to a member function of your class to install the vector.
-
- >Third, call it.
-
- >Optional step, generalize the concept and bubble it up to a base class, so
- >that you can reuse it. This can get tricky with multiple inheritence
- >with a virtual base class. (actually it is garunteed to choke bcc 3.0)
-
- This is more complex than necessary. The easy answer is: declare the member
- function as interrupt static, and just do the set_vect with it. Static
- members act just like C functions and hence have no this pointer. This is
- logically consistent since interrupt routines have no context. If the ISR
- needs to operate on an instance of the class, you must leave a global pointer
- around for it to use, and you can encapsulate this pointer in the class by
- making it static too. And yes, I've done this several times.
-
- Graham
- --
- Graham Stoney | "a Perl script is correct if it's halfway
- Flip Dibner fan club, "Hi Flip!" | readable and gets the job done before your
- Ph: +61 2 805-2909 Fax: -2929 | boss fires you." L. Wall & R. Schwartz
-