delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/20/22:06:55

Message-ID: <20010721020505.30662.qmail@web9903.mail.yahoo.com>
Date: Fri, 20 Jul 2001 19:05:05 -0700 (PDT)
From: Lets Go Canes <letsgonhlcanes AT yahoo DOT com>
Subject: Re: [OT] About const int
To: djgpp AT delorie DOT com
In-Reply-To: <9j9086$ogr$1@nets3.rz.RWTH-Aachen.DE>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Hi all.

I beg to differ.  As long as the compiler provides a switch to allow
the behavior as defined by the standard, then it is conforming.  There
is no reason why the default behavior cannot be to maximize the
potential for optimization, which would require assuming there are no
aliases.

And I will concede in advance that it is also a valid opinion
that the default behavior should be standard-conforming as you suggest.


--- Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de> wrote:
> Lets Go Canes <letsgonhlcanes AT yahoo DOT com> wrote:
> > Hi all.
> 
> > What you are doing is called "aliasing".  Many compilers would give
> you
> > the same result even if you removed the "const" qualifier.  
> 
> No. At least not any correct compilers conforming to Standard C in
> its
> traditional version dated 1989/1990, and I strongly believe those to
> be the overwhelming majority of compilers in use these days. 
> Standard
> C requires that all such side effects, whether by pointer aliasing or
> other means, be respected correctly, to a certain extent: no two such
> side effects are allowed to affect the same object between any two
> "sequence points".  A compiler that doesn't account for such side
> effects is broken beyond recognition. The program at hand does have
> undefined behaviour, but not because of aliasing.
> 
> C++ is no different from C, in this respect, to the best of my
> knowledge.
> 
> In fact, this aliasing issue is one of the reasons C programs can
> sometimes not be optimized as perfectly as some programmers want them
> to be -- it's one of the main reasons some people still insist coding
> in language like FORTRAN.  That's why, in the new C99 standard, a
> keyword was introduced that allows the programmer to state explicitly
> that a particular variable is not aliassed by any pointer:
> "restrict".
> 
> > Basically, the compiler doesn't know that "k" is a pointer to the
> > same memory occupied by "j" (i.e., "k*" is an alias for "j"), and
> so
> > if it already has the value of "j" in a register, it will use it,
> > even though you just changed the value of "j" via the "k*" alias.
> 
> If it did that, it'd be a severly broken compiler.
> 
> -- 
> Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
> Even if all the snow were burnt, ashes would remain.


=====
--------------
Lets Go Canes!

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019