delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/23/06:46:45

From: "Alexei A. Frounze" <dummy_addressee AT hotmail DOT com>
Newsgroups: alt.comp.lang.learn.c-c++,comp.os.msdos.djgpp
Subject: Re: Extern int [][]
Date: Fri, 23 Mar 2001 06:39:57 -0500
Organization: Global Crossing Telecommunications
Lines: 52
Sender: UNKNOWN AT 209-130-221-42 DOT nas1 DOT roc DOT gblx DOT net
Message-ID: <99fckc$h04$1@node17.cwnet.frontiernet.net>
References: <_msu6.644$I81 DOT 6431 AT nntp1 DOT chello DOT se>
NNTP-Posting-Host: 209-130-221-42.nas1.roc.gblx.net
X-Trace: node17.cwnet.frontiernet.net 985347532 17412 209.130.221.42 (23 Mar 2001 11:38:52 GMT)
X-Complaints-To: abuse AT frontiernet DOT net
NNTP-Posting-Date: 23 Mar 2001 11:38:52 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Daniel Eliasson" <danieleliasson AT chello DOT se> wrote in message
news:_msu6.644$I81 DOT 6431 AT nntp1 DOT chello DOT se...
> Hi, I've got a little problem that I need some help with. Actually, there
> are two.
>
> Here goes:
>
> 1. In a function, I declare the following variables:
>
> const int GRIDSIZE = 128;
> int grid[GRIDSIZE][GRIDSIZE];

1st of all, if you really want to have an array of adynamic size, use
malloc(),free(),realloc() and forget about the above stuff. If you don't
need arrays of variable size, define your GRIDSIZE as follows:
  #define GRIDSIZE 128

> When I need to use it in another function, how do I get it with an extern
> keyword? I've tried extern int grid, extern int grid[][] and extern int
> grid[GRIDSIZE][GRIDSIZE]
>
> The last one works, but it seems as it declares a new local variable
called
> grid instead of giving me access to the one I want.
> How do I import it?

"extern" doesn't create new variables. it helps to locate external stuff...

> 2. The compiler says that "storage size of `weaponCache' isn't constant"
> weaponCache is declared like this:
>
> const int MAXWEAPONS = 10;
> char *weaponCache[MAXWEAPONS];
>
> This, I suppose, is because of this error:
> "ANSI C++ forbids initialization of member `MAXWEAPONS'
> making `MAXWEAPONS' static"

As I said, declare the size using an immediate value like 10 (or "#define
MAXWEAPONS 10" and use MAXWEAPONS) but don't do that using a variable. It
leads to problems.

Good Luck
--
Alexei A. Frounze
alexfru [AT] chat [DOT] ru
http://alexfru.chat.ru
http://members.xoom.com/alexfru/
http://welcome.to/pmode/



- Raw text -


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