Related articles |
---|
Possible to write compiler to Java VM? (I volunteer to summarize) seibel@sirius.com (Peter Seibel) (1996-01-17) |
Re: Possible to write compiler to Java VM? macrakis@osf.org (1996-02-09) |
Aliasing in ISO C (was: Re: Possible to write compiler to Java VM?) rfg@monkeys.com (1996-02-13) |
Re: Aliasing in ISO C stevec@pact.srf.ac.uk (1996-02-14) |
Re: Aliasing in ISO C rfg@monkeys.com (1996-02-16) |
Re: Aliasing in ISO C jplevyak@violet-femmes.cs.uiuc.edu (1996-02-16) |
Re: Aliasing in ISO C cdg@nullstone.com (1996-02-16) |
Re: Aliasing in ISO C dlmoore@ix.netcom.com (1996-02-17) |
Languages: The Bigger the Uglier (was: Re: Aliasing in ISO C) rfg@monkeys.com (1996-02-19) |
Re: Aliasing in ISO C cliffc@ami.sps.mot.com (1996-02-19) |
Re: Languages: The Bigger the Uglier (was: Re: Aliasing in ISO C) jgm@CS.Cornell.EDU (1996-02-19) |
[5 later articles] |
From: | rfg@monkeys.com (Ronald F. Guilmette) |
Newsgroups: | comp.compilers |
Date: | 16 Feb 1996 00:43:46 -0500 |
Organization: | Infinite Monkeys & Co. |
References: | 96-01-037 96-02-082 96-02-116 |
Keywords: | C, design, GC |
Stavros Macrakis <macrakis@osf.org> wrote:
> There are also several features [in C] that make certain
> optimizations pretty much impossible, namely the possibility of
> almost arbitrary aliasing.
Ronald F. Guilmette <rfg@monkeys.com> wrote:
>This is a fairly common misconception about C, IMHO.
>
>The C standard is pretty clear in saying that in the following
>function, it is permissible to avoid the second indirection and load
>from *p1... assuming that you still have the value previously loaded
>from *p1 in a register somewhere:
>
> volatile int i;
> volatile char ch1, ch2;
>
> void foobar (char *p1, int *p2)
> {
> ch1 = *p1;
> *p2 = i;
> ch2 = *p1;
> }
>
>In other words, the C standard is pretty clear in saying that C only
>supports aliasing of (i.e. multiple pointers to) ``compatible'' (which
>in practice usually means ``identical'') types. In other cases, the C
>standard makes few guarantees.
I find I must offer my apologies to readers of this newsgroup. I
misspoke.
The _actual_ rules in cases like these are given in section 6.3 (final
paragraph) of the ISO/ANSI C standard.
My own statements were based upon the rules given in section 6.3.16.1
(Semantics, second paragraph), but these seem to apply only in some
limited cases involving unions and not to the general case of
non-identical-type aliasing which can be achieved (in C) via pointer
casts.
As two respondants have pointed out to me (in private E-mail) my
assertions about permissible optimizations on the code sample shown
above _would have beeen true_ if I had just used the type `float' or
some other type in place of the type `char' everywhere in my example.
(Section 6.3, last paragraph contains a special dispensation for
`character types' in particular, and allows any object, or part
thereof, to be accessed via an lvalue having some character type.)
My thanks to Ray Hayes <hayes@microunity.com> and Volker Barthelmann
<volker@vb.franken.de> for calling my attention to my error.
--
-- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
---- E-mail: rfg@monkeys.com ----------- Purveyors of Compiler Test Suites -
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.