Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: extern array as a pointer Date: Tue, 12 Jul 2016 09:28:58 -0700 Organization: None to speak of Lines: 32 Message-ID: References: <27db6ff2-216f-41c6-a9e0-c06d206f5262@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="10518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0KePcLXWGTUZJqGMPPEcE" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:MnfH9howqVsq9+OQKHPNT9olM3c= sha1:V4BqxPbkrU5NhpkOEeHvaDykwSg= Xref: csiph.com comp.lang.c:90282 BartC writes: > On 12/07/2016 11:06, sinbad wrote: >> why does the following program crash at line# 20. >> Is it even legal to define array as an integer >> pointer while infact it's original definition is >> single dimensional array or five elements. [...] >> 5 int array[5]; [...] >> 16 extern int *array; [...] > > You have a normal array in one module which is defined as a pointer to > array in another, assuming arr was meant to be array. No, it's declared (not defined) as a pointer to int, not a pointer to an array. A pointer to an array would be something like extern int (*a)[]; or extern int (*a)[5]; > Try writing: > > extern int array[]; Yup. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"