Article View: comp.std.c
Article #1927Re: A question on volatile accesses
From: Henry Spencer
Date: Sat, 03 Nov 1990 23:18
Date: Sat, 03 Nov 1990 23:18
37 lines
1815 bytes
1815 bytes
In article <2388@lupine.NCD.COM> rfg@lupine.ncd.com (Ron Guilmette) writes: > volatile int *ip; > i = *++ip; > >I'd like to know if the standard allows the incrementation of `ip' >to occur *after* the volatile access. It depends on what you are asking. If I am not mistaken, it is proper for the change to `ip' -- the variable -- to occur only after the access. However, the access itself *must* use the incremented value, even if that value has not yet been written back into the variable; the definition of the prefix `++' operator demands this. >In other words, could the program above legally be treated as: > i = *ip; > ++ip; No, although it could be treated as: i = *(ip + 1); ++ip; The volatility of the thing pointed at, by the way, has absolutely no bearing on the issue (except insofar as a kludged-in implementation of `volatile' may have introduced bugs). >This seems entirely counter-intutive to me, and yet one supposedly ANSI >C compiler provides such a treatment. Your use of the word "supposedly" is appropriate. The way you asked this implies that this doesn't happen if the thing pointed at is not `volatile'. My diagnosis would be as mentioned above: somebody kludged `volatile' into a compiler that originally didn't support it, and broke the prefix `++' operator in the process. -- "I don't *want* to be normal!" | Henry Spencer at U of Toronto Zoology "Not to worry." | henry@zoo.toronto.edu utzoo!henry
Technical Details
Message-ID:
<1990Nov3.231856.20556@zoo.toronto.edu>Path:
arc1-ca.pugleaf.net!utzoo!henryReferences:
<2388@lupine.NCD.COM>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: A question on volatile accesses Message-ID: <1990Nov3.231856.20556@zoo.toronto.edu> Organization: U of Toronto Zoology References: <2388@lupine.NCD.COM> Date: Sat, 3 Nov 90 23:18:56 GMT