Path: utzoo!attcan!uunet!wuarchive!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ucselx.sdsu.edu!bionet!agate!shelby!neon!Gang-of-Four!dkeisen From: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Newsgroups: comp.lang.c Subject: Re: extern char *foo vs. extern char foo[] Message-ID: <1990May30.064303.11951@Neon.Stanford.EDU> Date: 30 May 90 06:43:03 GMT References: <1990May30.001219.23564@uunet!unhd> Sender: news@Neon.Stanford.EDU (USENET News System) Distribution: comp Organization: Sequoia Peripherals Lines: 29 In article <1990May30.001219.23564@uunet!unhd> rg@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@Gang-of-Four.Stanford.EDU Office: (415) 967-5644 1447 N. Shoreline Blvd. Mountain View, CA 94043