From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3275 invoked by alias); 23 Nov 2006 17:27:51 -0000 Received: (qmail 3218 invoked by uid 22791); 23 Nov 2006 17:27:50 -0000 X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 23 Nov 2006 17:27:42 +0000 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GnIMD-0007lP-AT for gdb@sources.redhat.com; Thu, 23 Nov 2006 18:27:29 +0100 Received: from 73-198.umostel.ru ([82.179.73.198]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 23 Nov 2006 18:27:29 +0100 Received: from ghost by 73-198.umostel.ru with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 23 Nov 2006 18:27:29 +0100 To: gdb@sources.redhat.com From: Vladimir Prus Subject: Re: Variable values before initialisaton Date: Thu, 23 Nov 2006 17:27:00 -0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit User-Agent: KNode/0.10.2 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: 2006-11/txt/msg00161.txt.bz2 Rob Quill wrote: > Hi, > > Sorry to ask to many questions in one day. but I was wondering fi > anyone could explain why a variable can have a value before it has > been declared. > > In my code I have: > > int i = 0; > int j = 2; > int k = 3; > > and if I print the value of k any time before it has been set to 3, it > get it being equal to a very large number, rather than it not being in > the current scope. Is this a debugging thing, or something to do with > the way the code is compiled, or something else? You're extremely lucky you've int variables, and not C++ classes, and not trying to call member functions of those. The gdb/gcc combination has the bad habit of including not-yet-created variables in the list of local variables. I don't think anybody's working on a fix. - Volodya