Related articles |
---|
Re: Help: How to determine big/little endian? doconnor@sedona.intel.com (1995-08-17) |
Re: Help: How to determine big/little endian? cwf@research.att.com (Chris Fraser) (1995-08-25) |
Re: Help: How to determine big/little endian? daniels@cse.ogi.edu (1995-09-13) |
Re: Re: Help: How to determine big/little endian? robison@kai.com (Arch Robison) (1995-09-21) |
Newsgroups: | comp.compilers |
From: | Arch Robison <robison@kai.com> |
Keywords: | architecture, C, standards |
Organization: | Compilers Central |
References: | 95-08-120 95-09-008 95-09-107 |
Date: | Thu, 21 Sep 1995 16:34:52 GMT |
> The fetch of an int from the union after storing a char is strictly illegal.
As a developer of a very aggressive optimizer for C/C++, I wish it
were illegal. Unfortunately, the C standard (and C++ draft standard)
say otherwise. See the end of Section 3.3 of the ANSI C standard and
the end of Section 5.0 of the ANSI working paper for C++. Both are
explicit that *any* object can be accessed as a character type.
It is perhaps unfortunate that C does not distinguish between bytes
for bit-twiddling and bytes for characters, but that's the way the
C/C++ languages have evolved.
Hence the code
> union { char c; int i; } u;
> u.i = 0; u.c = 1;
> swap = (u.i == 1) != IR->little_endian;
does not require that u be qualified as volatile in order to work correctly.
Arch D. Robison Kuck & Associates Inc.
robison@kai.com 1906 Fox Drive
217-356-2288 Champaign IL 61820
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.