What causes wrong printf result of sizeof(&arr) in Microsoft Visual C++ 6.0?

40 Views Asked by At

In Microsoft Visual C++ 6.0, if I compile and run code as following:

#include "stdafx.h"

int main(int argc, char* argv[])
{
    int arr[5] = {1,2,3,4,5};
    printf("%d\n", sizeof &arr);
    printf("%d\n", sizeof(&arr));

    return 0;
}

The result is:

20
20

However, the result of other compiler such as gcc is:

4
4

Is this a bug of VC6 or it just follows a different compile rule?

The type of &arr should be an array pointer(int (*)[5]), so the result should be the size of a pointer rather than that of an array. Therefore, I think it is a bug of VC6.0. Analysis for this from assembler language side will be helpful.

0

There are 0 best solutions below