I don't get the error with the following

K

Kenneth Lantrip

code ================

const int Population = 50000;

typedef struct {
int IQ;
int Persistance;
int Account;
int AccStmt;
int Recruiter;
} pplstrk;

static pplstrk Person[Population];

============= endcode

gcc compile error:

pscam.c:25: error: variable-size type declared outside of any function


Is that not the way is supposed to be done? Did I learn a wrong way of
doing it?

Thanks.
 
T

those who know me have no need of my name

in comp.lang.c i read:
const int Population = 50000;

const qualified variables are not constants, merely read-only.
static pplstrk Person[Population];

thus this is a variable length array, which is only allowed within block
scope.
Is that not the way is supposed to be done? Did I learn a wrong way
of doing it?

you seem to have learned c++.
 
K

Kenneth Lantrip

those said:
in comp.lang.c i read:

const int Population = 50000;


const qualified variables are not constants, merely read-only.

static pplstrk Person[Population];


thus this is a variable length array, which is only allowed within block
scope.

Is that not the way is supposed to be done? Did I learn a wrong way
of doing it?


you seem to have learned c++.
LOL, :)

Yea, I got it fixed by making another #define

Seams, that not all compilers are created equil.

Thanks.
 
M

Martin Ambuhl

Kenneth said:
code ================

const int Population = 50000;

Population is a variable. If you need a constant, as for an array size
in a declaration, #define it.
typedef struct {
int IQ;
int Persistance;
int Account;
int AccStmt;
int Recruiter;
} pplstrk;

static pplstrk Person[Population];

============= endcode

gcc compile error:

pscam.c:25: error: variable-size type declared outside of any function


Is that not the way is supposed to be done?
No.

Did I learn a wrong way of
doing it?

Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top