Discussion:
Evaluate sizeof(T) in watch window
(too old to reply)
Martin T.
2009-09-22 08:17:12 UTC
Permalink
Hi all.

sizeof(T) is calculated at compile time.

However, the only way to get at the numeric value of sizeof(T) I've
found so far is to add a codeline int x = sizeof(T); and then check x in
the watch window.

Is it somehow possible to let sizeof(T) be evaluated by the debugger (or
even better display the value the compiler generates?)

cheers,
Martin
David Lowndes
2009-09-23 23:33:54 UTC
Permalink
Post by Martin T.
sizeof(T) is calculated at compile time.
However, the only way to get at the numeric value of sizeof(T) I've
found so far is to add a codeline int x = sizeof(T); and then check x in
the watch window.
Is it somehow possible to let sizeof(T) be evaluated by the debugger (or
even better display the value the compiler generates?)
Hi Martin,

Occasionally I find myself debugging and would like to know what
sizeof(T) (and _countof) is giving me.

Other than dropping into the disassembly view and checking the values
that way, I can't see a way of seeing the value of sizeof in the
debugger.

I suggest that you file a bug/suggestion report for it against Visual
Studio on the MS connect web site. If you post a link back to your
suggestion report here I'll add a vote to it as I think it'd be a
useful addition if it's not too difficult for MS to achieve.

Dave
Ben Voigt [C++ MVP]
2009-09-24 14:32:37 UTC
Permalink
Post by David Lowndes
Post by Martin T.
sizeof(T) is calculated at compile time.
However, the only way to get at the numeric value of sizeof(T) I've
found so far is to add a codeline int x = sizeof(T); and then check
x in the watch window.
Is it somehow possible to let sizeof(T) be evaluated by the debugger
(or even better display the value the compiler generates?)
Hi Martin,
Occasionally I find myself debugging and would like to know what
sizeof(T) (and _countof) is giving me.
Other than dropping into the disassembly view and checking the values
that way, I can't see a way of seeing the value of sizeof in the
debugger.
I suggest that you file a bug/suggestion report for it against Visual
Studio on the MS connect web site. If you post a link back to your
suggestion report here I'll add a vote to it as I think it'd be a
useful addition if it's not too difficult for MS to achieve.
Type layout information is in the .pdb, so it shouldn't be difficult.

Be careful however of macros. Many Win32 API types have both ANSI and
Unicode versions with different sizes, and the debugger isn't going to do
the macro expansion the compiler does. As a quick example, sizeof (TCHAR),
sizeof (LPARAM), sizeof (LONG) aren't going to work in the debugger,
although it should be possible to make sizeof(char) and sizeof (wchar_t)
work and so on.
Post by David Lowndes
Dave
Alex Blekhman
2009-09-24 16:57:08 UTC
Permalink
As a quick example, sizeof (TCHAR), sizeof (LPARAM), sizeof
(LONG) aren't going to work in the debugger, although it should
be possible to make sizeof(char) and sizeof (wchar_t) work and
so on.
Actually, VC++ debugger shows sizeof values for built-in types as
well as variables in watch window without any problem.

Alex
David Lowndes
2009-09-24 17:40:57 UTC
Permalink
Post by Alex Blekhman
Actually, VC++ debugger shows sizeof values for built-in types as
well as variables in watch window without any problem.
Well spotted Alex, I was only looking for it in the debug tooltip
facility. It also works from the immediate window (as you'd expect).

Pity _countof isn't catered for even though it is template magic
rather than a builtin operator.

Dave
Ben Voigt [C++ MVP]
2009-10-16 01:19:29 UTC
Permalink
Post by David Lowndes
Post by Alex Blekhman
Actually, VC++ debugger shows sizeof values for built-in types as
well as variables in watch window without any problem.
Well spotted Alex, I was only looking for it in the debug tooltip
facility. It also works from the immediate window (as you'd expect).
Pity _countof isn't catered for even though it is template magic
rather than a builtin operator.
Isn't it? If you put an array in the watch window, don't you get the
dimensions listed as part of the type information?
Post by David Lowndes
Dave
__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
__________ Information from ESET NOD32 Antivirus, version of virus signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
David Lowndes
2009-10-16 07:15:35 UTC
Permalink
Post by Ben Voigt [C++ MVP]
Post by David Lowndes
Pity _countof isn't catered for even though it is template magic
rather than a builtin operator.
Isn't it? If you put an array in the watch window, don't you get the
dimensions listed as part of the type information?
It isn't - in the same (more obvious) way as sizeof. Sometimes I find
I just want to check what value will be passed elsewhere.

Dave

Loading...