Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Denver Mods 4/2/84) 6/24/83; site drutx.UUCP Path: utzoo!watmath!clyde!floyd!harpo!ulysses!mhuxl!houxm!hogpc!houxe!drutx!jas From: jas@drutx.UUCP Newsgroups: net.lang.c Subject: Re: extern declaration inconsistency Message-ID: <132@drutx.UUCP> Date: Wed, 4-Apr-84 12:46:16 EST Article-I.D.: drutx.132 Posted: Wed Apr 4 12:46:16 1984 Date-Received: Thu, 5-Apr-84 01:53:05 EST References: <1538@mit-eddie.UUCP> Organization: AT&T Information Systems Laboratories, Denver Lines: 25 To paraphrase the question: Defining a global array "char ch[ 32 ];" in one file and declaring it externally as "extern char *ch" in another file causes bad craziness ("core dump"). Is this a bug or a feature? It is most emphatically a feature. An array of characters is not the same thing as a character pointer. Lying to the compiler about the type of an external variable will result in severe retribution. To wit: a reference to ch in the file in which it was defined as an array of 32 chars will be automatically dereferenced by the compiler, i.e., converted to the address of the first element of the array, because arrays are automatically dereferenced when they appear in an expression. A reference to ch in a file in which it was declared as "extern char *" will cause the compiler to issue code retrieving the POINTER VALUE STORED AT THAT LOCATION, i.e., to take the first several chars in the array ("several" usually = 2 or 4, depending on the machine), and interpret them as a pointer to a character somewhere. Interpreting the CONTENTS of "Hi, Mom!" as a character pointer will usually make you point at something you later wish you hadn't pointed at. Jim Shankland ..!ihnp4!druxy!jas