From owner-freebsd-questions@FreeBSD.ORG Sat Mar 15 17:08:28 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3B27E106566B for ; Sat, 15 Mar 2008 17:08:28 +0000 (UTC) (envelope-from chuckr@chuckr.org) Received: from mail8.sea5.speakeasy.net (mail8.sea5.speakeasy.net [69.17.117.10]) by mx1.freebsd.org (Postfix) with ESMTP id 285AB8FC1A for ; Sat, 15 Mar 2008 17:08:27 +0000 (UTC) (envelope-from chuckr@chuckr.org) Received: (qmail 19079 invoked from network); 15 Mar 2008 17:08:27 -0000 Received: from april.chuckr.org (chuckr@[66.92.151.30]) (envelope-sender ) by mail8.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 15 Mar 2008 17:08:27 -0000 Message-ID: <47DC0136.5020707@chuckr.org> Date: Sat, 15 Mar 2008 13:02:46 -0400 From: Chuck Robey User-Agent: Thunderbird 2.0.0.6 (X11/20071107) MIME-Version: 1.0 To: Derek Ragona References: <6.0.0.22.2.20080314171533.023f7c88@mail.computinginnovations.com> In-Reply-To: <6.0.0.22.2.20080314171533.023f7c88@mail.computinginnovations.com> X-Enigmail-Version: 0.95.5 OpenPGP: id=F3DCA0E9; url=http://pgp.mit.edu Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-questions Subject: Re: C compiler issue perhaps? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Mar 2008 17:08:28 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Derek Ragona wrote: > At 05:10 PM 3/14/2008, Doug Hardie wrote: >> I have a program I was testing with gdb. I was trying to figure out >> why c.rmonths was always zero when it should have been 6. Stepped >> through using the gdb n command. Here is the output: >> >> (gdb) >> 215 c.rmonths = (edate - tdate) / toMONTHS; >> (gdb) >> 223 c.dial_in = u.dial_in[0]; >> (gdb) >> 224 c.dsl = u.dsl[0]; >> (gdb) p c.rmonths >> $1 = 0 >> (gdb) p c >> $2 = {fa = 0, pwp = 0, disp_email = 0, imonths = 0, rmonths = 6, >> type = 73 'I', cd = 0 '\0', dial_in = 82 'R', dsl = 0 '\0', >> dsl_kit = 0 '\0', ip = 0 '\0', domain = 0 '\0', n_domain = 0 '\0', >> renewal = 89 'Y', program = "I\000\000"} >> (gdb) p c->rmonths >> $3 = 6 >> (gdb) p c.rmonths >> $4 = 6 >> >> >> Notice, the first time i print it its zero. The second time its 6. >> What gives here? I have seen this before but couldn't pin it down. >> The program is not compiled with any optimization. It is in a shared >> library though. > > It is hard to tell without the code you used. I would put some printf's > in the code and see what and when that variable gets set to in actual > running code. 2points: (1) yes, you are right, without the source code, any guesses are at the same level as black magic, useless (2) if the user is learning to use gdb, then it is really bad manners to suggest that printfs should be used. While I have made massive use of printfs before I got used to gdb, gdb is incredibly more powerful, can do any and all that any prints might accomplish, and anyone who is willing to learn to use that debugger should be encouraged, not given bad habits that really should be a fallback only to environments where gdb won't work. > > -Derek > -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFH3AE2z62J6PPcoOkRAsOeAJ9ZcF4K9Rtonrw5oQXVF3opoxvBjgCcDGJR szL8DpVrdPjMMpV4+I+bTg0= =RKOo -----END PGP SIGNATURE-----