From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26054 invoked by alias); 15 Apr 2004 13:27:46 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 26032 invoked from network); 15 Apr 2004 13:27:45 -0000 Received: from unknown (HELO mgr2.xmission.com) (198.60.22.202) by sources.redhat.com with SMTP; 15 Apr 2004 13:27:45 -0000 Received: from [198.60.22.201] (helo=mgr1.xmission.com) by mgr2.xmission.com with esmtp (Exim 3.35 #1) id 1BE6u8-0002jw-02; Thu, 15 Apr 2004 07:27:44 -0600 Received: from [198.60.22.20] (helo=xmission.xmission.com) by mgr1.xmission.com with esmtp (Exim 4.30) id 1BE6u8-0002wG-R4; Thu, 15 Apr 2004 07:27:44 -0600 Received: from llewelly by xmission.xmission.com with local (Exim 3.35 #1 (Debian)) id 1BE6u8-00037d-00; Thu, 15 Apr 2004 07:27:44 -0600 To: "Hamilton, Ian" Cc: "'gcc-help@gcc.gnu.org'" References: <8EAC52A94CD8D411A01000805FBB37760615AFE3@gbrwgcms02.wgc.gbr.xerox.com> From: llewelly@xmission.com Date: Thu, 15 Apr 2004 13:27:00 -0000 In-Reply-To: <8EAC52A94CD8D411A01000805FBB37760615AFE3@gbrwgcms02.wgc.gbr.xerox.com> Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 MIME-Version: 1.0 Subject: Re: Self-referring const array initialisation Content-Type: text/plain; charset=us-ascii X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on mgr1.xmission.com X-Spam-Level: X-Spam-Status: No, hits=0.3 required=8.0 tests=NO_REAL_NAME autolearn=no version=2.63 X-SA-Exim-Mail-From: llewelly@xmission.com X-SA-Exim-Version: 3.1 (built Wed Aug 20 09:38:54 PDT 2003) X-SA-Exim-Scanned: Yes X-SW-Source: 2004-04/txt/msg00183.txt.bz2 "Hamilton, Ian" writes: > Hi there > > Here is a test program to illustrate a problem in some code > I have inherited: > > #include > > const int array1[5]= > { > 1, > 2, > 3, > 4, > 5 > }; > > const int array2[5]= > { > 1, > array2[0] + 1, > array2[1] + 1, > array2[2] + 1, > array2[3] + 1, > }; > > int main() > { > printf ("Array values:\n\n"); > printf("array1 array2\n"); > > printf(" %i %i\n", array1[0], array2[0]); > printf(" %i %i\n", array1[1], array2[1]); > printf(" %i %i\n", array1[2], array2[2]); > printf(" %i %i\n", array1[3], array2[3]); > printf(" %i %i\n", array1[4], array2[4]); > } > > > If I build and run this on a Sun/Sparc/Solaris system using > gcc version 2.95.2, I get the following output: > > Array values: > > array1 array2 > 1 1 > 2 2 > 3 3 > 4 4 > 5 5 > > > However, if I use gcc version 3.3.2, I get this output: > > Array values: > > array1 array2 > 1 1 > 2 1 > 3 1 > 4 1 > 5 1 FWIW, on i386-freebsd5.2, gcc 3.4 release cannidate gives the same output as gcc 2.95.2 . So I think this bug is fixed in 3.4 (but it is still present in 3.3.3). I can't find the bug report, however. [snip] > My question is whether this sort of self-reference is allowed by > the C and/or C++ standards. In other words, is this a compiler bug, > or a bug in the above code? I am nearly certain C++ allows this. I can't find anything in 8.5.1 that disallows it.