Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!decwrl!amdcad!nucleus!tim From: tim@nucleus.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: Compilers and programming style (was Re: A question of style) Message-ID: <28716@amdcad.AMD.COM> Date: 9 Jan 90 15:19:03 GMT References: <1989Dec22.100135.2903@gdt.bath.ac.uk> <4367@rtech.rtech.com> <1989Dec31.153241.16479@gdt.bath.ac.uk> <649@codonics.COM> <1990Jan5.100042.26760@gdt.bath.ac.uk> <2283@dataio.Data-IO.COM> <534@bbxsda.UUCP> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc., Austin, Texas Lines: 32 Summary: Expires: Sender: Followup-To: In article <534@bbxsda.UUCP> scott@bbxsda.UUCP (Scott Amspoker) writes: | In article <2283@dataio.Data-IO.COM> bright@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@amd.com)