|[10 earlier articles]|
|Re: Help: How to determine big/little endian? email@example.com (1995-08-25)|
|Re: Help: How to determine big/little endian? firstname.lastname@example.org (1995-08-26)|
|Re: Help: How to determine big/little endian? email@example.com (Michael Meissner) (1995-09-01)|
|Re: Help: How to determine big/little endian? firstname.lastname@example.org (1995-09-01)|
|Re: Help: How to determine big/little endian? email@example.com (1995-09-03)|
|Re: Help: How to determine big/little endian? firstname.lastname@example.org (1995-09-13)|
|Re: Help: How to determine big/little endian? email@example.com (1995-09-26)|
|From:||firstname.lastname@example.org (Bill Davis)|
|Keywords:||C, architecture, standards|
|References:||95-08-120 95-09-008 95-09-107|
|Date:||Tue, 26 Sep 1995 16:29:15 GMT|
email@example.com (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 184.108.40.206, "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?
Return to the
Search the comp.compilers archives again.