extern char *foo vs. extern char foo[]
Dave Eisen
dkeisen at Gang-of-Four.Stanford.EDU
Wed May 30 16:43:03 AEST 1990
In article <1990May30.001219.23564 at uunet!unhd> rg at unhd.unh.edu.UUCP (Roger Gonzalez ) writes:
>
>According to K&R, there should be no difference between the two extern
>defs in my subject header. In fact, the second form (char foo[]) should
>get translated into the first. Unfortunately, it doesn't. Here's a
>more detailed example of what I mean:
>
>FILE #1:
>
> char hello[100];
>FILE #2:
>
> extern char *hello;
No, these are not the same thing. char [] and char * are two different
types and funny things happen when you declare variables incorrectly.
An array is treated as a pointer to the first element when used in an
expression or when passed as a function parameter, this does not
mean that an array and a pointer are the same thing. And (as you pointed
out) you cannot declare a variable as one and hope to get the other.
--
Dave Eisen Home: (415) 323-9757
dkeisen at Gang-of-Four.Stanford.EDU Office: (415) 967-5644
1447 N. Shoreline Blvd.
Mountain View, CA 94043
More information about the Comp.lang.c
mailing list