[NTLUG:Discuss] OT C question
Johnny Cybermyth
djcybermyth at sbcglobal.net
Tue Feb 21 12:31:07 CST 2006
Ah ha! Patrick, you have shed light on the matter clearly and
completely! I would be very glad to buy you lunch!
I kept insisting the myarray WAS a pointer to a character and had all
the rights and privileges therein, but I didn't consider the linker vs
compiler perspectives. I now completely see why adding the & operator
in my function parameter list worked when I was using the mismatched
referencing.
A very heartfelt thanks to you! I hope others found this as insightful
as I did.
Thank you very much to everyone else who spent some time out of their
lives thinking about this and made some good comments as well.
--Johnny
Patrick R. Michaud wrote:
>
>
> Aha, this is indeed the problem. Since file1.c defines myarray
> as being an array of characters, your extern statement needs to match.
>
> "But char* is the same as char[]," I hear people say. Actually,
> in this case it's not.
>
> The statement
>
> unsigned char myarray[5];
>
> allocates five bytes and sets "myarray" as a constant symbol
> that points to the first byte of the array. Most notably,
> "myarray" is -not- a pointer as it would be if this had been
> an unsigned char* definition. Perhaps a contrasting example
> will help:
More information about the Discuss
mailing list