delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/23/09:19:16

Date: Fri, 23 Mar 2001 19:23:21 +0530 (IST)
From: Mridul Muralidharan <ec97027 AT matrix DOT reccal DOT ernet DOT in>
To: dummy_addressee AT hotmail DOT com
cc: Djgpp mailing list <djgpp AT delorie DOT com>
Subject: Re: Extern int [][]
In-Reply-To: <99fckc$h04$1@node17.cwnet.frontiernet.net>
Message-ID: <Pine.LNX.4.04.10103231914590.1100-100000@matrix.reccal.ernet.in>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Fri, 23 Mar 2001, Alexei A. Frounze wrote:
> "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
> 
	Actually ,AFAIK , const int var_name is better way to do the above
as compared to #define in C++.
also in C++ , u are encouraged to use const in the place of #define
anyway.

> > 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...

right .

> > 2. The compiler says that "storage size of `weaponCache' isn't constant"
> > weaponCache is declared like this:
> >
> > const int MAXWEAPONS = 10;
> > char *weaponCache[MAXWEAPONS];

when i tried out the above , i didn't get any such error ! (tried it on
linux and djgpp )

Mridul Muralidharan
S8 Electronics and Communication
Regional Engineering College
Calicut
India

------------------------------------------------------------------------------  
If the code and the comments disagree, then both are probably wrong.
                -- Norm Schryer

All generalizations are false, including this one.
                -- Mark Twain

/earth is 98% full ... please delete anyone you can.

        - fortune





- Raw text -


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