sizeof bug

James Nicolson jamesATitixs.com
Wed Sep 15 18:08:00 GMT 1999


/*
This is some weird interaction between typedef, sizeof, and argument
passing.  I would expect all the sizeofs to return 16, but mysteriously
it returns 4 in one case.

GCC version: gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)
OS: Linux 2.2.5-15 (Redhat 6.0)
Hardware: Intel Pentium II
*/

#include <stdio.h>

typedef unsigned char ArrayType[16];

void foo(ArrayType arrayInstance)
{
    printf("In foo, sizeof(arrayInstance) = %d, sizeof(ArrayType) =
%d\n",
        sizeof(arrayInstance), sizeof(ArrayType));
}

int
main(int argc, char *argv[])
{
    ArrayType arrayInstance;

    printf("In main, sizeof(arrayInstance) = %d, sizeof(ArrayType) =
%d\n",
        sizeof(arrayInstance), sizeof(ArrayType));
    foo(arrayInstance);
}



More information about the Gcc-bugs mailing list