Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!ucsd!rutgers!att!whuts!homxb!houxs!beyer From: beyer@houxs.ATT.COM (J.BEYER) Newsgroups: comp.std.c Subject: Re: volatile registers (was: The world is not ready for 'volatile') Summary: How about global variables accessed by signal handlers? Keywords: volatile Message-ID: <1103@houxs.ATT.COM> Date: 5 Jan 89 19:12:26 GMT References: <141@bms-at.UUCP> <275@twwells.uucp> <15166@mimsy.UUCP> <2337@cuuxb.ATT.COM> Organization: AT&T BL Holmdel NJ USA Lines: 25 In article <2337@cuuxb.ATT.COM>, dlm@cuuxb.ATT.COM (Dennis L. Mumaugh) writes: > In article <9316@ihlpb.ATT.COM> nevin1@ihlpb.UUCP > (55528-Liber,N.J.) makes some comments about volatile that seem > to reflect many people's understanding. > > The concept "volatile" should not occur in any general C program. > This feature exists only for the stand alone, the real time and > the kernel hacker. > I disagree with this statement. Consider a program with a global variable that can be accessed by the 'main' program and a signal handler. On receipt of the signal, the signal handler might change the value of the global variable. When the signal handler returns, the 'main' program might observe the value of the global variable. Were this variable not declared volatile, the main program's code might be optimized so that the changed value would not be detected. Were the main program be stuck in a 'busy-loop' waiting for the global variable to change, and an optimizer (or clever compiler) optimized the test outside the loop, the main program would never get out. You may not care for this programming style, but it is legal and it is done. -- Jean-David Beyer A.T.&T., Holmdel, New Jersey, 07733 houxs!beyer