I don't get the error with the following

Discussion in 'C Programming' started by Kenneth Lantrip, Jul 18, 2004.

  1. 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.
     
    Kenneth Lantrip, Jul 18, 2004
    #1
    1. Advertising

  2. 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
     
    those who know me have no need of my name, Jul 18, 2004
    #2
    1. Advertising

  3. 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.
     
    Kenneth Lantrip, Jul 18, 2004
    #3
  4. 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.
     
    Martin Ambuhl, Jul 18, 2004
    #4
  5. On Sun, 18 Jul 2004 04:44:21 GMT, in comp.lang.c , Kenneth Lantrip
    <> 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 =---
     
    Mark McIntyre, Jul 18, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jalkadir
    Replies:
    2
    Views:
    405
  2. sqlsurfing
    Replies:
    0
    Views:
    897
    sqlsurfing
    Jan 27, 2010
  3. mt

    I don't understand the following..

    mt, Aug 4, 2011, in forum: C Programming
    Replies:
    4
    Views:
    394
    Paul N
    Aug 10, 2011
  4. Chad
    Replies:
    12
    Views:
    662
  5. ÕÔ±û·å

    why the following HereDoc print don't work?

    ÕÔ±û·å, Dec 8, 2004, in forum: Perl Misc
    Replies:
    29
    Views:
    312
    Sherm Pendley
    Dec 20, 2004
Loading...

Share This Page