From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28857 invoked by alias); 16 Jul 2009 17:28:19 -0000 Received: (qmail 28847 invoked by uid 22791); 16 Jul 2009 17:28:19 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Jul 2009 17:28:13 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MRUkV-0002kn-9D for gdb@sources.redhat.com; Thu, 16 Jul 2009 17:28:08 +0000 Received: from mn-69-34-67-62.sta.embarqhsd.net ([69.34.67.62]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 16 Jul 2009 17:28:03 +0000 Received: from grant.b.edwards by mn-69-34-67-62.sta.embarqhsd.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 16 Jul 2009 17:28:03 +0000 To: gdb@sources.redhat.com From: Grant Edwards Subject: Re: printing static const variables Date: Thu, 16 Jul 2009 17:28:00 -0000 Message-ID: References: <2C11E6EB-A5C0-4A12-8DC3-87E73C7755AC@ericgorr.net> <97A121F2-C4CB-4244-9F71-1D0B9BA60638@ericgorr.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: slrn/pre0.9.9-102 (Linux) X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-07/txt/msg00107.txt.bz2 On 2009-07-16, Eric Gorr wrote: > I still see the same problem if change the test function to: > > Boolean TestFunction( int val ) > { > static const int doubleByteDegreeMark = 42; > static int anotherVar = 12; > > return ( val == doubleByteDegreeMark || val == anotherVar ); > } > > Now, I suppose it is still possible that the compiler will have simply > optimized this to: > > Boolean TestFunction( int val ) > { > static int anotherVar = 12; > > return ( val == 42 || val == anotherVar ); > } > > or something. More likely it'll be optimized to Boolean TestFunction( int val ) { return ( val == 42 || val == 12 ); } There's no requirement that the compiler have a setting that doesn't optimize your function to that shown above. Since anotherVar isn't visible outside TestFunction, and isn't assigned to inside TestFunction, the compiler is free to treat it as a constant. -- Grant Edwards grante Yow! You were s'posed at to laugh! visi.com