Compilers and programming style (was Re: A question of style)

Tim Olson tim at nucleus.amd.com
Wed Jan 10 02:19:03 AEST 1990


In article <534 at bbxsda.UUCP> scott at bbxsda.UUCP (Scott Amspoker) writes:
| In article <2283 at dataio.Data-IO.COM> bright at dataio.Data-IO.COM (Walter Bright) writes:
| >volatile int *p;
| >*p;		/* has side effects and must not be optimized away	*/
| 
| Just curious - what kind of code should be generated for the above
| C fragment?

The integer pointed to by p should be accessed from memory and thrown
away (this may be useful in talking to certain peripheral devices).
For example:

w "t.c",L3/C3:  q: Expression has no side-effects.

;f(int *q, volatile int *p)
;{
;       *q;
;       *p;
        load    0,0,gr96,lr3
;}      jmpi    lr0
        nop


The expression "*q;" generated no code and produced a compiler warning
that it had no side-effects.  However, the expression "*p;", since p
was declared as a pointer to a volatile object, generates an access to
that object which is then subsequently thrown away.


	-- Tim Olson
	Advanced Micro Devices
	(tim at amd.com)



More information about the Comp.lang.c mailing list