Related articles |
---|
[10 earlier articles] |
Re: Help: How to determine big/little endian? nr@cs.purdue.edu (1995-08-25) |
Re: Help: How to determine big/little endian? doug@netcom.com (1995-08-26) |
Re: Help: How to determine big/little endian? meissner@cygnus.com (Michael Meissner) (1995-09-01) |
Re: Help: How to determine big/little endian? mab@wdl.loral.com (1995-09-01) |
Re: Help: How to determine big/little endian? erik@kroete2.freinet.de (1995-09-03) |
Re: Help: How to determine big/little endian? daniels@cse.ogi.edu (1995-09-13) |
Re: Help: How to determine big/little endian? wdavis@dw3f.ess.harris.com (1995-09-26) |
Newsgroups: | comp.compilers |
From: | wdavis@dw3f.ess.harris.com (Bill Davis) |
Keywords: | C, architecture, standards |
Organization: | Harris GISD |
References: | 95-08-120 95-09-008 95-09-107 |
Date: | Tue, 26 Sep 1995 16:29:15 GMT |
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?
--
Bill Davis
wdavis@dw3f.ess.harris.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.