Compiler

greenspun.com : LUSENET : Steve Heller's books : One Thread

Can you clear this up for me please Steve,

I'm working my way through the C++ Training Guide under Windows 95, and have come across something which puzzles me. The Compiler seemed to install OK, g032-v2 looked fine, and sample code from the disc and code which I write myself compiles and runs, no problem. But when I run it under the debugger using trace... I can step through the program using z [enter] but the variable values which you mention in the book just don't appear on my screen.

Also, and maybe this is related, concerning Vect1 and your discussion with Susan about variable initialisation, and what would happen if the five weights entered happen to all be 0 (zero). You say that I should expect a message similar to :

"You have tried to use element 51082 of a vector which has only five elements. "

Well, I tried that several times and the output is always the same. I don't get any message, just:

The Highest weight was: 0 The Second Highest weight was: 0 The Third Highest weight was: 0

Am I going crazy or just missing something obvious that's staring me in the face?

Thanks Tony.

-- Tony Pritchard (majordisaster@tesco.net), September 05, 1999

Answers

Compiler questions

Tony:

I can step through the program using z [enter] but the variable values which you mention in the book just don't appear on my screen.

What does appear on your screen? Anything?

You say that I should expect a message similar to :

"You have tried to use element 51082 of a vector which has only five elements. "

Well, I tried that several times and the output is always the same. I don't get any message, just:

The Highest weight was: 0 The Second Highest weight was: 0 The Third Highest weight was: 0

Am I going crazy or just missing something obvious that's staring me in the face?

No, you're not going crazy. The problem is simply that when you're dealing with uninitialized variables, you don't know what is going to happen. In your case, it happened that the values in those uninitialized variables were 0. Therefore, the program worked all right. However, if someone else did the same thing, they might get different results. That's why you have to make sure to initialize your variables before use.

-- Steve Heller (stheller@koyote.com), September 14, 1999.


Moderation questions? read the FAQ