daniels@cse.ogi.edu (Scott David Daniels) writes:
|>The fetch of an int from the union after storing a char is strictly
|>illegal. Since it is illegal, the compiler may assume the fetch must be
|>tied to a corresponding store, and the "u.i = 0;" strictly dominate the
|>fetch. So, my ``optimization'' should be a legal compiler optimization.
|>By making u volatile, each fetch and store must be accomplished by the
|>related sequence points, guaranteeing a strict order of
|> write u.i, write u.c, read u.i
|>Which is what we want.

According to the ANSI C standard, section 3.5.2.1, "The value of at most
one of the members can be stored in the union object at one time."
I assume this is where you get the claim that fetching an int after
storing a char is illegal. Thus, the volatile would not be a strictly
conforming fix either because the subsequent fetch would still
be illegal and the compiler would not be required to do anything.

On a practical basis, the real question is, "Why do you want to
know the difference?" If your code will execute the same on
both types (and a lot of code will do that) then don't worry about
the difference. If your code will execute differently, then don't
you already have a way to tell the difference using that code?