Re: sizeof on arrays and pointers

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: BRG (brg_at_nowhere.org)
Date: 01/20/05


Date: Thu, 20 Jan 2005 15:22:28 +0000

Doug Harrison [MVP] wrote:

> BRG wrote:
>
>>The following program produces different results on the five different
>>compilers I am using:
>>
>>---------------------------------
>>#include <stdio.h>
>>typedef char ctype[100];
>>int main()
>>{ char x[100], *y;
>> ctype c;
>> printf("\n%3ld %3ld", sizeof(x), sizeof(&x));
>> printf("\n%3ld %3ld", sizeof(y), sizeof(&y));
>> printf("\n%3ld %3ld", sizeof(c), sizeof(&c));
>> return 0;
>>}
>>---------------------------------
>>
>>These results are as follows:
>>
>>Compiler 1 Compiler 2 Compiler 3 Compiler 4 Compiler 5
>>100 100 100 100 100 4 100 2 100 100
>> 4 4 4 4 4 4 2 2 4 4
>>100 100 100 100 100 4 100 2 100 100
>>
>>VC++ produces the first of these and is claimed to be wrong by some who
>>think that the right answer is number three.
>>
>>Is this a bug in VC++?

Reported as a bug in VC8 (beta) and accepted for a fix in future
versions as it is already to late for VC8

    Brian Gladman



Relevant Pages

  • Re: Moving from C++ to VC++
    ... Doug Harrison [MVP] wrote: ... it's the return type for strtol. ... int, when int can be as small as 16 bits. ...
    (microsoft.public.vc.language)
  • Re: defragmenting memory
    ... Doug Harrison [MVP] wrote: ... int main ... cannot be said for "memory defragmentors". ...
    (microsoft.public.vc.language)
  • Re: fabs behaviour varies?
    ... it's interpreting the result as an int instead of double. ... definitely mess you up. ... Doug Harrison ... Visual C++ MVP ...
    (microsoft.public.vc.language)
  • Re: heeeeeeeeeeeeeeeellllllllllllllppppppppppppppppppppp
    ... the relational operators produce an int. ... Doug Harrison ... Visual C++ MVP ...
    (microsoft.public.vc.mfc)
  • Re: msaccess and dataset problems
    ... VC8 also has a different data access framework in the form of ... MFC which I believe still has native support for the dated DAO ... Microsoft MVP, MCSD ...
    (microsoft.public.vc.language)