Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!gatech!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.lang.c Subject: Re: volatile (in comp.lang.c) Summary: volatile is useful in portable code Message-ID: <186@proxftl.UUCP> Date: 18 May 88 15:11:37 GMT References: <2642@geac.UUCP> <225800029@uxe.cso.uiuc.edu> <4727@ihlpf.ATT.COM> <5367@bloom-beacon.MIT.EDU> Organization: Proximity Technology, Ft. Lauderdale Lines: 45 In article <5367@bloom-beacon.MIT.EDU>, peter@athena.mit.edu (Peter J Desnoyers) writes: > The debate over |volatile| seems to focus on one point: if this > keyword is only necessary for non-portable code, why does it have to > be part of the language? Volatile is useful in portable code. Here is the skeleton of one way to use it. #include volatile sig_atomic_t Sighappened; /* Must be THIS type. */ void sighandler( int signum ) { /* Ignore SIGINT until the previous one has been processed. Unfortunately, between the time of the signal and this call a SIGINT may cause the default action to be taken (this is implementation dependent). Grrrrr. */ signal(SIGINT, SIG_IGN); Sighappened = 1; } main() { signal(SIGINT, sighandler); while (1) { if (Sighappened) { ... handle the signal /* Permit SIGINT to be recognized again. */ Sighappened = 0; signal(SIGINT, sighandler); continue; } ... do something else } } (Pardon if this code has trivial flaws; I do not have easy access to an ANSI-ish compiler.)