delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/08/03:01:44

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: [Q] array declaration
Message-ID: <Pine.SGI.3.91.971007161047.19768A-100000@atmosp.physics.utoronto.ca>
NNTP-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
Organization: University of Toronto - Dept. of Physics
In-Reply-To: <61cskr$fh8$1@newton.pacific.net.sg>
Date: Tue, 7 Oct 1997 20:13:32 GMT
References: <61cskr$fh8$1 AT newton DOT pacific DOT net DOT sg>
Lines: 26
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Tue, 7 Oct 1997, Victor wrote:

> When I declare an array like this
> int foo[260];
> and then somewhere in the separate file I again declare it as
> extern int foo[260];
> the size of array is not checked, so second time I could have declared
> it as [280] without a warning.
> 
> The question is how to declare the array so that it's possible to have
> it's size checked to prevent mistakes.


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.  Then when the compiler sees a different array size in the file 
that allocates the array it will complain, so you will have to make the 
size correct in the header file and it will be correct everywhere else 
too.

Why do people have such an aversion to using header files?

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

- Raw text -


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