Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utcsri!flaps From: flaps@utcsri.UUCP Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Accessing data from an interrupt handler Message-ID: <5531@utcsri.UUCP> Date: Thu, 15-Oct-87 18:40:54 EDT Article-I.D.: utcsri.5531 Posted: Thu Oct 15 18:40:54 1987 Date-Received: Sat, 17-Oct-87 10:12:15 EDT References: <330@picuxa.UUCP> Reply-To: flaps@utcsri.UUCP (Alan J Rosenthal) Organization: University of Toronto Lines: 35 Xref: utgpu comp.sys.ibm.pc:7817 comp.lang.c:4663 Summary: gp@picuxa.UUCP (Greg Pasquariello X1190) writes, slightly edited by ajr: >I wrote a test program in MSC 4.0 [on the ibm-pc] that will >set up an interrupt handler... >The next thing I did was change the int >handler to increment a word of memory (a variable), >and when the interrupt was done being serviced, the C program printed the >value of the variable. Problem was, the value was ALWAYS 0. I then ran >the interrupt handler and the C code through >[a symbolic debugger], and found that the variable *WAS* being incremented. This may or may not be your problem, but you should be declaring this variable to be volatile. Otherwise, the compiler is free to compile something like the printf in: function() { static int i = 8; ... [no statements affecting the value of i] printf("%d\n",i); ... [no more statements affecting the value of i, or getting any pointers to it] } as: printf("%d\n",8); If you add in a 'volatile', the compiler is required to generate code which actually fetches the value every time you tell it to. ajr