delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/23/13:02:28

From: "Stefan Viljoen" <Stefan_Viljoen AT excite DOT com>
Newsgroups: alt.comp.lang.learn.c-c++,comp.os.msdos.djgpp
Subject: Re: Extern int [][]
Date: Fri, 23 Mar 2001 19:50:06 +0200
Organization: The South African Internet Exchange
Lines: 46
Message-ID: <99g2bo$dtt$5@ctb-nnrp2.saix.net>
References: <_msu6.644$I81 DOT 6431 AT nntp1 DOT chello DOT se>
NNTP-Posting-Host: pc53-01-p206.nt.saix.net
X-Trace: ctb-nnrp2.saix.net 985369784 14269 155.239.176.206 (23 Mar 2001 17:49:44 GMT)
X-Complaints-To: abuse AT saix DOT net
NNTP-Posting-Date: 23 Mar 2001 17:49:44 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
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];
>
> 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]

Extern means "outside this file" (I think!). I use it to, for example, make
one module "see" a variable that is declared in another module, "module"
referring to another .C file in the same project.

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

What you could do is to use a pointer, but I think that is not a good idea -
are you calling this function that you want to have access to these
variables from the function that contains their declaration?? As I
understand it, the whole point of function variables is to use them only in
the function in which they are declared - I think they are deallocated when
the function exits, right?
So why not just declare them globally and get it over with?

If you want to do variable arrays (erm - linked lists?) take a look at
http://home.intekom.com/rylan/ and go to the programming section. I have a
simple linked list demo program with full source that shows one way of how
it can be done.

Stefan Viljoen
F/EMS Dispatcher
Potchefstroom F/EMS
South Africa
http://home.intekom.com/rylan/


- Raw text -


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