Re: Correct ordering of write operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux