From: cberry AT cinenet DOT net (Craig Berry) Newsgroups: comp.os.msdos.djgpp Subject: Re: [Q] array declaration Date: 13 Oct 1997 16:48:53 GMT Organization: Cinenet Communications,Internet Access,Los Angeles;310-301-4500 Lines: 38 Distribution: world Message-ID: <61tjdl$mmm$1@marina.cinenet.net> References: NNTP-Posting-Host: hollywood.cinenet.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Paul Shirley (Paul AT no DOT spam DOT please) wrote: : In article , Eli Zaretskii : writes : >There are other solutions, but none of them is elegant. This happens : >to be one of the ugliest problems in C. : : The 'elegant' solution is to #define the array size in a header (the : same one you declare the array seems a good idea;) then use it in both : the declaration and definition of the array. : : so.. : #define MYSIZE (280) : extern char myarray[MSYIZE]; : : ...later... : #include : char myarray[MYSIZE]; : : This guarantees that all references to myarray see the same sized array. : (And makes sure that make will keep all uses in sync as a bonus.) Or, for the truly paranoid: In the header: #define MY_ARRAY_SIZE (260) typedef char MyArrayType[MY_ARRAY_SIZE]; extern MyArrayType myArray; Somewhere in the source which includes this header: MyArrayType myArray; --------------------------------------------------------------------- | Craig Berry - cberry AT cinenet DOT net --*-- Home Page: http://www.cinenet.net/users/cberry/home.html | Member of The HTML Writers Guild: http://www.hwg.org/ "Every man and every woman is a star."