## BUG: Bad Address for Anonymous Union/Struct Fields in VWB

Q117200

    1.00 1.50
    WINDOWS
    kbtool kbbuglist

    ----------------------------------------------------------------------
    The information in this article applies to:

     - The Visual Workbench Integrated Debugger included with:
       Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    ----------------------------------------------------------------------

    SYMPTOMS
    ========

    An anonymous union or structure has been defined without a name or a
    typedef definition. These variable types can be used when only one instance
    of a variable is necessary and when the data type is needed only within a
    single function.

    When using anonymous data types, the debugger may give an incorrect address
    for fields within the anonymous union or structure.

    RESOLUTION
    ==========

    To resolve the problem, you need to declare a local variable of the same
    type as the anonymous union or structure.

    STATUS
    ======

    Microsoft has confirmed this to be a bug with the Visual Workbench for
    Windows, versions 1.0 and 1.5. We are researching this problem and will
    post new information here in the Microsoft Knowledge Base as it is
    available.

    The problem does not occur with the Visual Workbench included with Visual
    C++ 32-bit Edition, version 1.0.

    MORE INFORMATION
    ================

    The sample code below can be used to illustrate this problem. Place a
    breakpoint before the "printf" statement, then place a watch on the address
    of local union structure members "w1" and "w0".

    Sample Code
    -----------

    /* Compile options needed: /Zi
    */

       #include <stdio.h>

       typedef unsigned long ULONG;
       typedef unsigned short USHORT;
       typedef unsigned long DWORD;
       typedef unsigned WORD;

       class ULONG64
       {
        public:
          union
          {
             struct
             {
                DWORD dw0;
                DWORD dw1;
             };
             DWORD rgdw[2];
             struct
             {
                WORD w2;
                WORD w3;
             };
             WORD rgw[4];
          };
        public:
          ULONG64(ULONG l) { dw0 = l; dw1 = 0; }
          ULONG64() { dw0 = 0; dw1 = 0; }
       };

       ULONG64& operator*=(ULONG64& ul, USHORT m)
       {
          union
          {
             DWORD dw;
             struct
             {
                WORD w0;
                WORD w1;
             };
          };

          dw = (ULONG)m * ul.w3 + w1;
          ul.w3 = w0;

          printf("&w0=%p &w1=%p\n", &w0, &w1);

          return ul;
       }

       int main()
       {
          ULONG64 ul(0x12345678);

          ul *= 1000;
          return 0;
       }

    Output
    ------

       &w0=3344 &w1=3346

    Watch Values
    ------------

       +&w0 = 0x3F67:0x3344
       +&w1 = 0x3F67:0x3344

    Additional reference words: 1.00 1.50
    KBCategory: kbtool kbbuglist
    KBSubcategory: WBDebug

Keywords : kb16bitonly
Issue type :
Technology :

Last Reviewed: December 22, 1999 © 2001 Microsoft Corporation. All rights reserved. Terms of Use.