Path: utzoo!attcan!uunet!microsoft!dans From: dans@microsoft.UUCP (Dan SPALDING) Newsgroups: comp.lang.c Subject: Re: sizeof() confusion Message-ID: <58808@microsoft.UUCP> Date: 5 Nov 90 18:05:24 GMT References: <9156@latcs1.oz.au> Reply-To: dans@microsoft.UUCP (Dan SPALDING) Organization: Microsoft Corp., Redmond WA Lines: 30 In article <9156@latcs1.oz.au> jacob@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