🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #10040

(none)

#10040
From: NEWSMGR
Date: Wed, 17 Oct 1990 09:17
126 lines
4920 bytes
Relay-Version: VMS News - V6.0 1/9/90 VAX/VMS V5.3; site kontu.utu.fi
Path: kontu.utu.fi!polaris.utu.fi!news.funet.fi!sunic!mcsun!uunet!tut.cis.ohio-state.edu!relay.eu.net!nixpbe!uucp
Newsgroups: gnu.gdb.bug
Subject: (none)
Message-ID: <9010152202.AX20544@unido.informatik.uni-dortmund.de>
From: nixpbe!uucp@relay.eu.net
Date: 15 Oct 90 22:02:48 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Approved: bug-gdb@prep.ai.mit.edu
Lines: 113

>From uucp Mon Oct 15 19:51 WST 1990 remote from nixsin
To: nixpbe!unido!gnu-gdb-bug
Path: nixsin!nixpbe!nixbur!linus!agate!shelby!snorkelwacker!mit-eddie!wuarchive!cs.utexas.edu!radar!cadillac!Pkg.Mcc.COM!steve
From: steve@Pkg.Mcc.COM (Steve Madere)
Newsgroups: gnu.gdb.bug
Subject: Ambiguous variable names in C++ code.
Message-ID: <1990Oct2.100854@Pkg.Mcc.COM>
Date: 2 Oct 90 15:08:54 GMT
Sender: news@cadillac.CAD.MCC.COM
Reply-To: steve@Pkg.Mcc.COM (Steve Madere)
Lines: 100



What follows is a copy of an EMail exchange about some problems
I've been having with gdb and g++ code.

-------------------------------------------------
To: interviews@interviews.stanford.edu
Subject: Ambiguous variables in IV source
Status: R


I've run across something while debugging my code and it leaves
me quite puzzled.  This is one of those features of C++
that I don't use because I just knew it would cause trouble.
Sure enough, it did.

This is actual gdb output:
-------------------------------------
(gdb) list 52,71
52      BrushRep::BrushRep (int* pattern, int c, int width) {
53          if (c != 0) {
54              if (
55                  _world->dash() == DashAll
56                  || width == 0 && _world->dash() == DashThin
57                  || width == 0 && _world->dash() == DashDefault
58              ) {
59                  count = c;
60                  info = new char[count];
61                  for (int i = 0; i < count; ++i) {
62                      *((char*)info + i) = char(pattern[i]);
63                  }
64              } else {
65                  count = 0;
66                  const int width = 32;
67                  const int height = 32;
68                  boolean bits[width];
69                  for (int i = 0; i < width; ++i) {
70                      bits[i] = PatternBit(i, pattern, c);
71                  }
(gdb) print width
$38 = 3
(gdb) info locals
pattern = (int *) 0xf7fff380
c = 2
width = 3
$this = (WorldRep *) 0x1
$this = (WorldRep *) 0x1
$this = (WorldRep *) 0x1
i = -134220632
width = 32
height = 32
bits = {1, 0, 0, 0, 4160746136, 472060, 0, 0, 1, 1, 0, 0, 1, 1, 4226,
100592, 10
0596, 0, 4198528, 472056, 472060, 0, 4, 4, 4161953232, 4294963032, 8,
52428, 416
0746448, 128, 2, 0}
i = 1
gc = (GC) 0xffffef58
x = 2
-----------------------------------------

Notice that width is defined twice.  I can't tell which one is 
supposed to be used to control the for loop at line 69.  If I
type 'print i' I get some nonsense huge negative number (i is
also defined twice in this context).

I always thought that writing ambiguous code was not a particularly
safe practice.

The reason I am debugging this stuff is that I am getting a
bus error at  some random location (probably from one of these
routines stomping on somebody else's pointers).

Steve Madere
-------------------------------------------
Date: Mon, 1 Oct 90 11:01:34 +0100
From: <Name deleted>
To: steve%pkg@mcc.com
Subject: Ambig. var. in InterViews
Status: R

The code is not ambiguous, but your debugger is brain-damaged.

The code uses nested variables with the same name, which may
be a questionable practice, but is't perfectly legal in C++
(and in most other languages).  On the other hand, gdb
apparently cannot keep track of what scope you were in when
you printed the variables -- I think that *three* occurences
of `this' is the most glaring deficiency in your example.

To answer your question: the code is not ambiguous; the `width'
used in line 69 is the variable defined in line 66.

--------------------------------------------------------

Anybody know how I can specify which particular instance of a
varible I want when there appear to be several copies locally
defined?

Steve Madere
steve@pkg.mcc.com
Technical Details
Message-ID: <1AE6AFF4820720618C@kontu.utu.fi>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!KONTU.UTU.FI!NEWSMGR

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5053,c313bf9b7e840c49
X-Google-Attributes: gidf5053,public
X-Google-ArrivalTime: 1990-10-17 02:17:00 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!KONTU.UTU.FI!NEWSMGR
From: NEWSMGR@KONTU.UTU.FI
Newsgroups: gnu.gdb.bug
Subject: (none)
Message-ID: <1AE6AFF4820720618C@kontu.utu.fi>
Date: 17 Oct 90 09:17:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 126
Approved: bug-gdb@prep.ai.mit.edu
Posted: Wed Oct 17 10:17:00 1990