Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   I don't get the error with the following (http://www.velocityreviews.com/forums/t434576-i-dont-get-the-error-with-the-following.html)

Kenneth Lantrip 07-18-2004 04:05 AM

I don't get the error with the following
 
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.

those who know me have no need of my name 07-18-2004 04:11 AM

Re: I don't get the error with the following
 
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++.

--
a signature

Kenneth Lantrip 07-18-2004 04:44 AM

Re: I don't get the error with the following
 
those who know me have no need of my name wrote:
> 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.

Martin Ambuhl 07-18-2004 05:54 AM

Re: I don't get the error with the following
 
Kenneth Lantrip wrote:

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

Mark McIntyre 07-18-2004 10:46 PM

Re: I don't get the error with the following
 
On Sun, 18 Jul 2004 04:44:21 GMT, in comp.lang.c , Kenneth Lantrip
<nunya@bidny.ok> wrote:

>those who know me have no need of my name wrote:
>> in comp.lang.c i read:
>>>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++.

>
>Yea, I got it fixed by making another #define


>Seams, that not all compilers are created equil.


No! Read the previous poster's explanation again.

Your code was wrong - not the compiler.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


All times are GMT. The time now is 12:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.