www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/14/18:01:16

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: <Pine DOT SGI DOT 3 DOT 91 DOT 971007161047 DOT 19768A-100000 AT atmosp DOT physics DOT utoronto DOT ca>
NNTP-Posting-Host: hollywood.cinenet.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Paul Shirley (Paul AT no DOT spam DOT please) wrote:
: In article <Pine DOT SUN DOT 3 DOT 91 DOT 971008110125 DOT 28262M-100000 AT is>, Eli Zaretskii
: <eliz AT is DOT elta DOT co DOT il> 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 <the header>
: 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."

- Raw text -


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