FIX: Can't Watch Values of Nondimensioned Array Parameters

Last reviewed: September 18, 1997
Article ID: Q117161
1.00 1.50 1.51 WINDOWS kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The Visual Workbench Integrated Debugger included with:

        - Microsoft Visual C++ for Windows, versions 1.0, 1.5, and 1.51
    

SYMPTOMS

When 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.

RESOLUTION

This 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).

STATUS

Microsoft 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 INFORMATION

The 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
KBCategory: kbtool kbfixlist kbbuglist
KBSubcategory: WBDebug
Keywords : kb16bitonly WBDebug kbbuglist kbfixlist kbtool
Version : 1.00 1.50 1.51
Platform : WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.