sizeof() confusion
Dan SPALDING
dans at microsoft.UUCP
Tue Nov 6 05:05:24 AEST 1990
In article <9156 at latcs1.oz.au> jacob at latcs1.oz.au (Jacob L. Cybulski) writes:
-Being relatively new to C, I found a bit of a problem with a THINK C program
-that goes more or less like this :-
-
-typedef unsigned char Pattern[8];
-
-void foo (Pattern x)
-{
-/* 0 */ printf("%d\n", sizeof(Pattern); /* prints 8 */
-/* 1 */ printf("%d\n", sizeof(x)); /* prints 4 */
-/* 2 */ printf("%d\n", sizeof(*x)); /* prints 1 */
-/* 3 */ printf("%d\n", sizeof((Pattern) x); /* illegal */
-/* 4 */ printf("%d\n", sizeof(*((Pattern *) x)); /* prints 8 */
-}
-
In C, the base of an array is synonomous with a pointer to an element (the
base element) of that array. Therefore, Pattern is 8 bytes, x is 4 (the size
of all pointers on the Mac) and *x will be 1 byte (an unsigned char).
Hope this helps.
--
------------------------------------------------------------------------
dan spalding -- microsoft systems/languages -- microsoft!dans
"there has not been a word invented that would convey my indifference to
that remark." - paraphrase from hawkeye pierce
More information about the Comp.lang.c
mailing list