This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Correct ordering of write operations
- From: John Love-Jensen <eljay at adobe dot com>
- To: Ryan Lortie <desrt at desrt dot ca>, GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 19 Feb 2008 08:04:27 -0600
- Subject: Re: Correct ordering of write operations
Hi Ryan,
The compiler correctly deduced that the side-effect of q = 42; is not
needed.
Making q volatile tells the compiler that the side-effect of q = 42; cannot
be determined to not be needed.
> By the C99 specification I believe I shouldn't need to use volatile in
> this case, but by experimenting with GCC it appears that I do. Based on
> my reading, my understanding tells me that GCC is diverging from the
> specification here.
GCC is compliant with the specification, at least on this issue.
> Can someone please explain to me why my understanding is incorrect or
> why GCC chooses to diverge?
The compiler can fully analyze the use of q, and can determine that q = 42;
is a not needed side-effect, since q is not accessed between there and the
subsequent q = 7;.
HTH,
--Eljay