Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.COM (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: extern char *foo vs. extern char foo[] Message-ID: <227@taumet.COM> Date: 30 May 90 16:51:22 GMT References: <1990May30.001219.23564@uunet!unhd> Reply-To: steve@taumet.UUCP (Stephen Clamage) Distribution: comp Organization: Taumetric Corporation, San Diego Lines: 34 In article <1990May30.001219.23564@uunet!unhd> rg@unhd.unh.edu.UUCP (Roger Gonzalez ) writes: > >A little history: I know C inside and out, and don't need any "I think"s. Evidently not. >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. Not true. > char hello[100]; > extern hello[]; In both declarations, hello means the address of an array. hello is a (link-time) constant and may not be assigned to. > extern char *hello; hello means the address of a variable which *contains* the address of an array (or of a variable, which would be an array of size 1). hello may be assigned to, so as to point to another array. >So. Why are my compilers so stupid? Do others >behave the same way, or am I just unfortunate enough to have lousy software? Other compilers better behave the same way, since the language definition requires it. It is a common misunderstanding that arrays and pointers are in some sense "the same thing". This is one case where they are not the same thing. The difference is discussed in Chapter 5 of old original K&R, and this difference has not changed. It is still a difference in ANSI C. -- Steve Clamage, TauMetric Corp, steve@taumet.com