Path: utzoo!utgpu!watmath!clyde!att!pacbell!ames!ucsd!chem.ucsd.edu!tps From: tps@chem.ucsd.edu (Tom Stockfisch) Newsgroups: comp.lang.c Subject: Re: const, volatile, etc [was Re: #defines with parameters] Message-ID: <377@chem.ucsd.EDU> Date: 2 Dec 88 08:30:21 GMT References: <674@quintus.UUCP> <117@halcdc.UUCP> <468@auspex.UUCP> <9016@smoke.BRL.MIL> <10919@ulysses.homer.nj.att.com> Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) Distribution: eunet,world Organization: Chemistry Dept, UC San Diego Lines: 27 In article <10919@ulysses.homer.nj.att.com> ggs@ulysses.homer.nj.att.com (Griff Smith) writes: >In article <9016@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes: >> "volatile" also serves a need. In fact, it directly addresses one of... >.... I blew several hours discovering that a flag >set by a signal handler had been optimized out of existence because it >wasn't declared volatile. If I were writing new software I would be >aware of the problem and use the proper declaration, but what am I to >do about fixing all the old stuff that now has subtle errors caused by >optimizations that used to be illegal? Presumably there are only a few 1. Turn off optimizations (perhaps only some of them) when compiling signal handler modules. All relevant flags should be declared static in these files. 2. Access the flags in other modules only via function calls to routines in the signal handler modules. Now the compiler can't optimize away references to the flags. Of course, if your compiler does extensive global optimization (accross modules), you may still be in trouble. -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu