On Sat Jan 29, 2005 at 11:42:28 +1100, Rick Welykochy wrote:
>I've been fiddling around with some MD5 code in coreutils,
>and discovered this weirdness with gcc:
>
>
>#include <stdio.h>
>
>void showsize(unsigned char arg[16])
>{
>        unsigned char stack[16];
>        fprintf(stderr,"[sizeof(arg) = %d]\n",sizeof(arg));
>        fprintf(stderr,"[sizeof(stack) = %d]\n",sizeof(stack));
>}
>
>int main()
>{
>        unsigned char m[16];
>        showsize(m);
>        return 0;
>}
>
>
>       
>The output:
>
>[sizeof(arg) = 4]
>[sizeof(stack) = 16]
>
>Can anyone explain why the size of arg differs from the array
>on the stack?
>
>Is C treating arg as a char* so that sizeof(arg) is sizeof(char*)?

From the ISOC99:

"When applied to an operand that has array type, the result is the
total number of bytes in the array"[84]

Footnote 84: When applied to a parameter declared to have array of
function type, the sizeof operator yields the size of the adjusted
(pointer) type (see 6.9.1)

Then in 6.9.1.10:

"... (Array expressions and functions designators as arguments were
converted to pointers before the call.)"

So yes, C is treating the arg as a char *.


Benno
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to