From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15832 invoked by alias); 18 Jun 2008 17:05:32 -0000 Received: (qmail 15823 invoked by uid 22791); 18 Jun 2008 17:05:32 -0000 X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 18 Jun 2008 17:04:58 +0000 Received: from mail.gnu.org ([199.232.76.166]:46609 helo=mx10.gnu.org) by fencepost.gnu.org with esmtp (Exim 4.67) (envelope-from ) id 1K913U-00070d-Sp for gcc@gnu.org; Wed, 18 Jun 2008 13:02:44 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1K915W-0002Qa-MN for gcc@gnu.org; Wed, 18 Jun 2008 13:04:55 -0400 Received: from synapse.neuralscape.com ([198.144.200.82]:37762 helo=neuralscape.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K915W-0002QS-3R for gcc@gnu.org; Wed, 18 Jun 2008 13:04:50 -0400 Received: from localhost.neuralscape.com ([127.0.0.1] helo=synapse.neuralscape.com) by neuralscape.com with esmtp (Exim 4.42) id 1K915U-000184-Kg; Wed, 18 Jun 2008 10:04:48 -0700 Received: (from shaeffer@localhost) by synapse.neuralscape.com (8.13.8/8.13.8/Submit) id m5IH4lPh004343; Wed, 18 Jun 2008 10:04:47 -0700 Date: Wed, 18 Jun 2008 17:05:00 -0000 From: Karen Shaeffer To: Joe Buck Cc: Andrew Pinski , Ian Lance Taylor , gcc@gnu.org Subject: Re: auto const ints and pointer issue Message-ID: <20080618170447.GA4179@synapse.neuralscape.com> References: <20080617174222.GA19409@synapse.neuralscape.com> <20080618014401.GA25773@synapse.neuralscape.com> <20080618035124.GA27477@synapse.neuralscape.com> <20080618164126.GN31678@synopsys.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080618164126.GN31678@synopsys.com> User-Agent: Mutt/1.4.2.2i X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2008-06/txt/msg00398.txt.bz2 On Wed, Jun 18, 2008 at 09:41:26AM -0700, Joe Buck wrote: > On Tue, Jun 17, 2008 at 08:51:24PM -0700, Karen Shaeffer wrote: > > I see your point. My sticking point is that the process is actually > > running on a physical machine. > > And that's the problem. You, like many C programmers, have in your head a > physical machine model where pointer variables are physical machine > addresses and other variables are physical memory locations. But C > doesn't necessarily work that way (except at -O0); if it did, programs > would run substantially slower. The compiler can make optimizations (like > reusing values in registers) in certain circumstances. Anywhere in the > standard where you see that a behavior is undefined, read that as meaning, > the compiler is allowed to produce an arbitrary code sequence, so it will > produce the fastest, or smallest, or simplest-to-implement sequence. > > > And the addresses, although virtual, > > do translate to a unique physical memory location. And, the value > > stored in that location cannot be 0 and 5 at the same time. > > Right, but since it's const, the compiler is allowed to assume that it > is, well, const! That means that if it has already read the value into > a register, it can assume that the register is still valid for the > remainder of the program execution, even if you decide to violate the > rules of C and change the "constant". That's why it appears to be > 0 and 5 at the same time. > > To get rid of that behavior, you'd have to force the compiler to read > every variable from memory every time, and not use registers at all. Thanks Joe, Hahaha. Let's let this thread die. You haven't added anything new that hasn't already been discussed. It's turning into noise. Thanks, Karen -- Karen Shaeffer Neuralscape, Palo Alto, Ca. 94306 shaeffer@neuralscape.com http://www.neuralscape.com