Path: utzoo!utgpu!watserv1!watmath!att!att!bu.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!ncifcrf!lhc!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.std.c Subject: Re: A question on volatile accesses Message-ID: <27407@mimsy.umd.edu> Date: 3 Nov 90 19:29:00 GMT References: <2388@lupine.NCD.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 In article <2388@lupine.NCD.COM> rfg@lupine.ncd.com (Ron Guilmette) writes: >Given ... volatile int *ip; ... i = *++ip; >I'd like to know if the standard allows the incrementation of `ip' >to occur *after* the volatile access. Yes. >In other words, could the program above legally be treated as: >... i = *ip; ++ip; ... No. The equivalent expansion is, instead, i = ip[1]; ++ip; /* or: tmp = ip + 1; i = *tmp; ip = tmp; */ Even if `ip' itself were volatile (`volatile int *volatile ip;') the same sequence could be used, since `volatile' really does not say much anyway. The main idea behind `volatile' is to make sure that loads and stores are not deferred beyond sequence points. Without volatile, the sequence i = *ip; ip++; i *= *ip; could be computed as x = ip[1]; y = ip[0]; i = x * y; ip += 2; whereas with it, the x and y above must be loaded in the other order. I am not at all certain whether ip must be altered between those operations (if ip itself were volatile, this would be true). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris