delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/08/09:49:47

Date: Wed, 8 Oct 1997 09:45:12 -0400 (EDT)
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
cc: djgpp AT delorie DOT com
Subject: Re: [Q] array declaration
In-Reply-To: <Pine.SUN.3.91.971008110125.28262M-100000@is>
Message-ID: <Pine.SGI.3.91.971008094204.9747B-100000@atmosp.physics.utoronto.ca>
MIME-Version: 1.0

On Wed, 8 Oct 1997, Eli Zaretskii wrote:

> 
> On Tue, 7 Oct 1997, Peter Berdeklis wrote:
> 
> > Put the extern declaration in a header file, which is included by any 
> > file which references the array, including the file that allocates the 
> > array.
> 
> I think this won't solve Victor's problem, because you still have to 
> declare the array in two different places.  One place is the header file 
> you are suggesting, where it should be declared extern:
> 
> 	extern char array[280];
> 
> The other place is that single source file which has to *define* the 
> array (so it gets allocated some space):
> 
> 	char array[280];

That's exactly the problem I was addressing Eli.

If you include the header file in the source file that defines the array, 
then the compiler will complain about a redefinition of the array only if 
the type or size of the array is different.  If the type and size of the 
extern declaration and the definition are the same there will be no 
complaint.

---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019