Click here to Skip to main content
16,004,927 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: help with playin wave files Pin
J. Dunlap19-May-03 19:06
J. Dunlap19-May-03 19:06 
GeneralWrite to a file. Pin
kjessee19-May-03 16:59
kjessee19-May-03 16:59 
GeneralRe: Write to a file. Pin
Dominik Reichl19-May-03 21:28
Dominik Reichl19-May-03 21:28 
GeneralStreamOut with large content Pin
blongtq19-May-03 15:48
blongtq19-May-03 15:48 
GeneralRe: StreamOut with large content Pin
Martyn Pearson19-May-03 21:18
Martyn Pearson19-May-03 21:18 
GeneralRe: StreamOut with large content Pin
blongtq20-May-03 16:43
blongtq20-May-03 16:43 
GeneralRe: StreamOut with large content Pin
Martyn Pearson20-May-03 22:52
Martyn Pearson20-May-03 22:52 
GeneralWatch Window Bug under /Zc:forScope Pin
Doug19-May-03 14:31
Doug19-May-03 14:31 
You use the compiler switch /Zc:forScope if you want standard C++ behavior for for loops with Microsoft extensions (/Ze). Standard behavior is to let a for-loop's initializer go out of scope after the for loop.

However, this switch APPEARS not to work if you are watching the value of a for-loop's initializer in a Watch Window

Consider the following code compiled with /Ze and /Zc:forScope:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<code>#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
float doug[3] = {0.0};

for (short i = 1; i < 3; i++)
{
doug[i] = 3.3;
} //next i

short i = 0;

short a = i;

cout << i << endl << a ;

return 0;
}</code>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Firstly, you get a compiler warning:

warning C4258: 'i' : definition from the for loop is ignored; the definition from the enclosing scope is used.

The warning is at the line:

<code> short i = 0;</code>
I claim that this warning is nonsense, since the definition of "i" should not exist at this point. How can you ignore something that does not exist?Cry | :((

Anyway, run the code past the for-loop and pause at the line:

<code> short i = 0;</code>
Note at this point that, according to the Watch Window

i = 3Cry | :((
a = -13108 (Why should "a" even exist at this point, albeit with a nonsense value?)Cry | :((

Now pause at the line:

<code> cout << i << endl << a;</code>
Note that the Watch Window says

i = 3
a = 0

In other words the Watch Window reports the value of "i" INCORRECTLY, whilst internally the program seems to have got the right idea.Cry | :(( Smile | :) Cry | :((

Pinch yourself and see if you are not hallucinating with the line:

<code> cout << i << endl << a ;</code>
Yup ... both "i" and "a" really do seem to have value = 0, BUT the Watch Window STILL says that i = 3! Confused | :confused: Confused | :confused:

(Incidently disabling Microsoft extensions altogether with /Za fixes the Watch Window problem)

This is all very unsettling for a beginner programmer.Confused | :confused: Confused | :confused:

2 Questions:

1. Can anyone shed any light or comment? Am I missing something?
2. According to the Watch Window, why does "a" seem to exist before getting to the line:

<code> short a = i;</code> ???Confused | :confused:

Thanks to all,


Doug



Doug
GeneralRe: Watch Window Bug under /Zc:forScope Pin
Maxwell Chen19-May-03 15:38
Maxwell Chen19-May-03 15:38 
GeneralRe: Watch Window Bug under /Zc:forScope Pin
Doug19-May-03 15:47
Doug19-May-03 15:47 
QuestionHow to convert a large DWORD to a string? Pin
mcgahanfl19-May-03 14:25
mcgahanfl19-May-03 14:25 
AnswerRe: How to convert a large DWORD to a string? Pin
Dave Bryant19-May-03 14:39
Dave Bryant19-May-03 14:39 
GeneralRe: How to convert a large DWORD to a string? Pin
mcgahanfl20-May-03 2:55
mcgahanfl20-May-03 2:55 
QuestionAccessing other users' My Documents folders? Pin
IGx8919-May-03 13:44
IGx8919-May-03 13:44 
GeneralCRecentFileList Pin
dings19-May-03 10:44
dings19-May-03 10:44 
QuestionPrinting with MFC? Pin
dings19-May-03 9:51
dings19-May-03 9:51 
AnswerRe: Printing with MFC? Pin
David Crow19-May-03 10:02
David Crow19-May-03 10:02 
GeneralRe: Printing with MFC? Pin
dings19-May-03 10:35
dings19-May-03 10:35 
GeneralSpy++ - like app Pin
Member 40241919-May-03 8:33
Member 40241919-May-03 8:33 
GeneralRe: Spy++ - like app Pin
Joaquín M López Muñoz19-May-03 9:04
Joaquín M López Muñoz19-May-03 9:04 
GeneralRe: Spy++ - like app Pin
Beer19-May-03 9:48
Beer19-May-03 9:48 
GeneralRe: Spy++ - like app Pin
Jeremy Falcon19-May-03 9:47
professionalJeremy Falcon19-May-03 9:47 
GeneralRe: Spy++ - like app Pin
Neville Franks19-May-03 12:08
Neville Franks19-May-03 12:08 
GeneralRe: Spy++ - like app Pin
Roger Allen20-May-03 5:43
Roger Allen20-May-03 5:43 
GeneralCHtmlView::OnBeforeNavigate2 problem Pin
rrrado19-May-03 5:26
rrrado19-May-03 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.