| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: C++ for beginners? |
From: John Beckett
On Mon, 22 Nov 2004 18:44:47 -0500, "Geo" wrote:
> char loglines{4096][256]
You probably need to master the basics before contemplating Paul's more
correct comments. The basics are:
1. A function variable ("auto") occupies stack memory. 2. Global
variables (defined outside functions) occupy data memory. 3. The qualifier
"static" has two meanings:
- On a function variable, it means use data memory, not stack.
- On a global variable, it means "visible here only".
The above is a rather crude summary. Anyway, you could solve your problem
by putting "static" in front of the array variable.
Alternatively, you could move the variable outside a function (in that
case, the "static" would not be required, but would be good
practice to indicate that you only intend the variable to be used from
within the current source module).
// Crude example.
#include
const int MAXLINES = 4096;
const int MAXLEN = 255;
static char loglines2[MAXLINES][MAXLEN+1];
void main()
{
static char loglines[MAXLINES][MAXLEN+1];
for ( int j = 0; j < MAXLINES; ++j )
sprintf(loglines[j], "%d Sample Log Text", j);
}
The above has TWO arrays (loglines2 is not used).
John
--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)SEEN-BY: 633/267 270 5030/786 @PATH: 379/45 1 396/45 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.