grantk@manta.NOSC.MIL (Kelly J. Grant) (06/26/91)
I'm working on 4.2BSD on a Sun. In one module I have a character array declared, 'char foo[20+1];'. In another module, I refer to foo using extern, ie.,'extern char *foo', and then attempted to use it in a printf(), which summarily caused a core dump. When I changed the reference to 'extern char foo[]', it worked properly. K&R2 does not seem to address this directly. I read about external definitions in the appendix, and the entire pointer chapter, but it does not reference this exact situation. Does anyone out there have a good explanation why the char * failed ? I know that a pointer can be treated differently (ie, incremented), but as an argument to a function it should not matter. What is actually occurring during the failure ? Many thanks in advance Kelly -- Kelly Grant grantk@manta.nosc.mil (619) 225-2508 Computer Sciences Corp ^^^^^^^^ Important: manta.UUCP won't get to me 4045 Hancock Street "If you are given lemons.....see if you can trade for San Diego, CA 92110 chocolate" - me
grantk@manta.NOSC.MIL (Kelly J. Grant) (06/27/91)
In article <2080@manta.NOSC.MIL>, grantk@manta.NOSC.MIL (Kelly J. Grant) writes:
[ a question shamelessly asked in the FAQ deleted in the interest of taste... ]
Thank you for all your replies. I have always checked the FAQ before and never
found my answer, so I got lazy. Sorry. You can stop sending flames, as we
finally ran out of marshmallows. :-)
The basic answer I wanted (kind of answered well in the FAQ) is why p[] is
different than *p as an external reference. The answer is the compiler
translates p[] into &p[0]. If you don't tell it p is an array, it does
not know to do this translation. p is actually nothing, but a symbol
whose reference was changed. Char *p expects p to be an actual pointer
(a concept a 10 year C veteran here couldn't come up with).
Thanks again
Kelly
--
Kelly Grant grantk@manta.nosc.mil (619) 225-2508
Computer Sciences Corp ^^^^^^^^ Important: manta.UUCP won't get to me
4045 Hancock Street "If you are given lemons.....see if you can trade for
San Diego, CA 92110 chocolate" - me