473,395 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Structs and pointers don't display in watch window???

Say I have a managed C++ app with some code that looks something like this:

void MyMethod()
{
struct Point { int x, y; };

Point* p = new Point;

p.x = 1;
p.y = 2;
....
}

During a debugging session, if I create a watch for the variable p, the
watch window does not display its contents. It says it is an invalid
pointer; Further more, if I create a watch for p->x or p->y, it says the
variable does not exist. If I change my code as follows:

struct Point { int x, y; };
....
void MyMethod()
{
Point* p = new Point;

p.x = 1;
p.y = 2;
....
}

then the Watch window correctly displays the value of p as a expandable
structure with a + sign that lets you see x and y as individual variables.

I also had something as simple as this:

{
int* pi = new int;
...
}

and the watch window displayed this value as invalid.

What's going on here anyway? I've experienced a lot of different cases where
the watch window just won't display the values of pointers and simple
structs, whereas in other cases it has no problems. Any suggestions would be
appreciated.
Nov 17 '05 #1
2 1374
Peter,
Say I have a managed C++ app with some code that looks something like this:
void MyMethod()
{
struct Point { int x, y; };

Point* p = new Point;

p.x = 1;
p.y = 2;
...
}

During a debugging session, if I create a watch for the variable p, the
watch window does not display its contents. It says it is an invalid
pointer; Further more, if I create a watch for p->x or p->y, it says the
variable does not exist. If I change my code as follows:

struct Point { int x, y; };
...
void MyMethod()
{
Point* p = new Point;

p.x = 1;
p.y = 2;
...
}

then the Watch window correctly displays the value of p as a expandable
structure with a + sign that lets you see x and y as individual variables.

I also had something as simple as this:

{
int* pi = new int;
...
}

and the watch window displayed this value as invalid.

What's going on here anyway? I've experienced a lot of different cases where the watch window just won't display the values of pointers and simple
structs, whereas in other cases it has no problems. Any suggestions would be appreciated.


I commented on this a while back on my weblog [1]. Perhaps it might help you
understand a bit what's going on...

[1] http://www.winterdom.com/weblog/archives/000067.html

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2
Thanks very much for this info. I suspected it had something to do with
managed/unmanaged code. The pointers in this weblog on the problem will
definitely help.

Peter

"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Peter,
Say I have a managed C++ app with some code that looks something like

this:

void MyMethod()
{
struct Point { int x, y; };

Point* p = new Point;

p.x = 1;
p.y = 2;
...
}

During a debugging session, if I create a watch for the variable p, the
watch window does not display its contents. It says it is an invalid
pointer; Further more, if I create a watch for p->x or p->y, it says the
variable does not exist. If I change my code as follows:

struct Point { int x, y; };
...
void MyMethod()
{
Point* p = new Point;

p.x = 1;
p.y = 2;
...
}

then the Watch window correctly displays the value of p as a expandable
structure with a + sign that lets you see x and y as individual
variables.

I also had something as simple as this:

{
int* pi = new int;
...
}

and the watch window displayed this value as invalid.

What's going on here anyway? I've experienced a lot of different cases

where
the watch window just won't display the values of pointers and simple
structs, whereas in other cases it has no problems. Any suggestions would

be
appreciated.


I commented on this a while back on my weblog [1]. Perhaps it might help
you
understand a bit what's going on...

[1] http://www.winterdom.com/weblog/archives/000067.html

--
Tomas Restrepo
to****@mvps.org

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jan-Henrik Grobe | last post by:
Hallo, I am coming to this newsgroup with a very strange Problem. I have two c++ files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in B.cpp I have stored the callback...
3
by: Christian F | last post by:
Hi, I'm a C-newbie and I would like to know if I am doing something wrong in the code below. It is working, but I'm afraid it might not be correct because I don't really understand everything of...
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
4
by: Austin | last post by:
I converted a project from VC6 to VC7. There is a problem in one class of this dll. ///Class1.h class CClass1: base class { private: int m_nTest; public : void Function1() }
6
by: Tau | last post by:
look my simple code below(vc8): double ends; ends=8.3; when i debug it, the variable ends cannot be displayed in the watch window. it just said "error: index '0' out of bound for...
5
by: Bidule | last post by:
Hi, I'm trying to sort structs defined as follows: struct combinationRec { float score; char* name; }; The number of structs and the length of the "name" field are not known
5
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say...
12
by: barcaroller | last post by:
Is it legal to compare the contents of two multi-field variables (of the same struct) using "==" and "!="? struct { int a; int b; } x,y; ...
17
by: Johan Tibell | last post by:
Could someone outline the pros and cons of typedefing pointers to structs like this? typedef struct exp_ { int val; struct exp_ *child; } *exp; (This is straight from memory so it might not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.