FIX: Can't Watch Values of Nondimensioned Array ParametersLast reviewed: September 18, 1997Article ID: Q117161 |
1.00 1.50 1.51
WINDOWS
kbtool kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSWhen trying to view an array of pointers that is passed to a function as a nondimensioned array, the debugger cannot display the array's values or displays incorrect values. This happens with both CodeView and the Visual C++ integrated debugger. The source file must be a C++ source file with a .CPP or .CXX extension.
RESOLUTIONThis problem is actually a special case of the one described in Knowledge Base article Q112984. The workaround is the same as in Q112984, with an additional step: Declare the function argument as a pointer rather than an array, as stated in article Q112984. For example, change a declaration that uses the array syntax:
void Function( char* Array[5] )to a declaration that uses pointer syntax:
void Function( char Array )Additionally, when you have traced into the function using the parameter, you must use an actual array subscript to access elements of the array in the watch window. For the example above, if you want to watch the second element, typing "Array[1],s" in the watch window causes the correct string to display (the ",s" format specifier is only necessary to view the variable as a string).
STATUSMicrosoft has confirmed this to be a bug in the products listed at the beginning of this article. This problem was corrected in Visual C++ 1.52. This is not a problem in the 32-bit debugger.
MORE INFORMATIONThe following sample demonstrates this problem. Step into the functions "ShowString()" and "ShowDoubles()", expanding "ary_pchar" and "dA", respectively, in the locals window. The values are not displayed correctly here or in the watch window if a watch is set on them.
Sample Code
// compiler options: /Zi /Od #include <stdio.h> // void ShowString( char ary_pchar ) // switch these two lines to void ShowString( char* ary_pchar[] ) // fix the problem { printf( "%s", ary_pchar[1] ); // break here } // void ShowDoubles( double dA ) // switch these two lines to void ShowDoubles( double *dA[] ) // fix the problem { int i; for (i = 0; i < 5; i++) { // break here printf( "%lf\n", *dA[i] ); } } void main(void) { char str[] = "TEST\n"; char* strArry[5]; double d[5], *pD[5]; int i; strArry[1] = str; for (i = 0; i < 5; i++) { d[i] = i; pD[i] = &d[i]; } ShowString( strArry ); ShowDoubles(pD); for (i = 0; i < 5; i++) { printf( "%lf\n", d[i] ); } } |
Additional reference words: 1.00 1.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |