This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]