const, volatile, etc [was Re: #defines with parameters]

Tom Stockfisch tps at chem.ucsd.edu
Fri Dec 2 18:30:21 AEST 1988


In article <10919 at ulysses.homer.nj.att.com> ggs at ulysses.homer.nj.att.com (Griff Smith) writes:
>In article <9016 at smoke.BRL.MIL>, gwyn at 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 at chem.ucsd.edu



More information about the Comp.lang.c mailing list