Re: Aliasing in ISO C

stevec@pact.srf.ac.uk (Stephen Clarke)
14 Feb 1996 21:35:36 -0500

          From comp.compilers

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)
Re: Aliasing in ISO C cliffc@ami.sps.mot.com (1996-02-19)
Re: Aliasing in ISO C Joris.Welkenhuysen@ping.be (1996-02-24)
| List of all articles for this month |

From: stevec@pact.srf.ac.uk (Stephen Clarke)
Newsgroups: comp.compilers,comp.std.c
Followup-To: comp.std.c
Date: 14 Feb 1996 21:35:36 -0500
Organization: University of Bristol, England
References: 96-01-037 96-02-082 96-02-116
Keywords: C, optimize, standards

Ronald F. Guilmette (rfg@monkeys.com) wrote:
: 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.


If I understand correctly, the part of the standard you are referring
to is 6.3 Expressions, where rules are given for the type of the
lvalue used to access an object's stored value ... but this section
allows any object to be accessed using a character type, so it seems
to me that *p1 could access an object of any type, including int,
which means that *p1 could access the same object as *p2.


This is just an unfortunate choice of types in the example. Given


volatile int i;
volatile long la, lb;


void foobar (long *p1, int *p2)
{
la = *p1;
*p2 = i;
lb = *p1;
}


I agree with you, though I've never been brave enough take advantage
of these aliasing restrictions in the compiler I work on!


Steve.
(Follow-ups to comp.std.c.)
--
--------------
Stephen Clarke,
PACT (Partnership in Advanced Computer Technologies)
Email: stevec@pact.srf.ac.uk
Mail : 10 Priory Road, Clifton, Bristol, BS8 1TU. UK.
Phone: +44 117 970 7188, Fax +44 272 707 171.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.