FIX: sizeof Gives Incorrect Size for Based Structure Pointers

Last reviewed: September 18, 1997
Article ID: Q116446
1.00 WINDOWS kbprg kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE) included with:

        - Microsoft Visual C++ for Windows, version 1.0
    

SYMPTOMS

The sizeof macro returns an incorrect size for based structure pointers in C++ code under the compact-memory, large-memory, and huge-memory models. In C code, sizeof returns 2 bytes for a based structure pointer, but the return value is 4 bytes in C++ code.

STATUS

Microsoft has confirmed this to be a problem with the C/C++ Compiler for MS- DOS, version 8.0. This problem was corrected with the C/C++ Compiler for MS- DOS, version 8.0c that was included with Visual C++ for Windows, version 1.5.

MORE INFORMATION

You can use the sample code below to reproduce this problem. If you compile the example as a C++ file, sizeof(t.left) returns 4 bytes and sizeof(test) returns 2 bytes. In a C file, both expressions return 2 bytes.

Sample Code

/* Compile options needed: /AL (/AC or /AH)
*/

   #include <stdio.h>

   typedef struct tree TREE;

   struct tree
   {
      int name;
      TREE __based( (__segment)__self ) *next;
   };

   int __based((__segment)__self) *test;

   void main(void)
   {
      struct tree t;

      t.name = 1;

      printf("sizeof(t)       = %d bits\n", sizeof(t) * 8);
      printf("sizeof(t.name)  = %d bits\n", sizeof(t.name) * 8);
      printf("sizeof(t.name)  = %d bits\n", sizeof(t.next) * 8);
      printf("sizeof(test) = %d bits\n", sizeof(test) * 8);
   }


Additional reference words: 8.00 1.00 fixlist8.00c fixlist1.50 buglist8.00
buglist1.00
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: CPPIss
Keywords : CPPIss kb16bitonly kbbuglist kbfixlist kbprg
Version : 1.00
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.