FIX: sizeof Gives Incorrect Size for Based Structure Pointers

ID: Q116446

1.00 WINDOWS kbprg kbfixlist kbbuglist

The information in this article applies to:

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          : kb16bitonly kbCompiler kbCPPonly kbVC kbbuglist kbfixlist
Version           : 1.00
Platform          : WINDOWS
Solution Type     : kbfix

Last Reviewed: September 22, 1997