Cannot allocate array

Discussion in 'C++' started by saneman, Aug 2, 2008.

  1. saneman

    saneman Guest

    I get the following error when I try to allocate the below code:

    cannot allocate an array of constant size 0

    int main() {
    int dim = 3;
    int b[dim][dim];

    return 0;
    }


    What am I doing wrong?
    saneman, Aug 2, 2008
    #1
    1. Advertising

  2. saneman

    Ian Collins Guest

    saneman wrote:
    > I get the following error when I try to allocate the below code:
    >
    > cannot allocate an array of constant size 0
    >
    > int main() {
    > int dim = 3;
    > int b[dim][dim];
    >
    > return 0;
    > }
    >
    >
    > What am I doing wrong?
    >

    Not using a C99 compiler.

    To be legal c++, you should uee a const:

    const size_t dim = 3;

    --
    Ian Collins.
    Ian Collins, Aug 2, 2008
    #2
    1. Advertising

  3. Ian Collins wrote:
    > saneman wrote:
    >> I get the following error when I try to allocate the below code:
    >>
    >> cannot allocate an array of constant size 0
    >>
    >> int main() {
    >> int dim = 3;
    >> int b[dim][dim];
    >>
    >> return 0;
    >> }
    >>
    >>
    >> What am I doing wrong?
    >>

    > Not using a C99 compiler.
    >
    > To be legal c++, you should uee a const:
    >
    > const size_t dim = 3;


    const int dim = 3; would be fine too.
    Juha Nieminen, Aug 2, 2008
    #3
    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. Roedy Green
    Replies:
    3
    Views:
    3,248
    Roedy Green
    Aug 14, 2003
  2. rveloso

    popen cannot allocate memory

    rveloso, Apr 4, 2006, in forum: C Programming
    Replies:
    1
    Views:
    1,167
    Keith Thompson
    Apr 4, 2006
  3. valerio
    Replies:
    3
    Views:
    370
  4. Replies:
    13
    Views:
    12,921
    Kai-Uwe Bux
    Jan 22, 2007
  5. Andreas
    Replies:
    1
    Views:
    1,687
    Piet van Oostrum
    Mar 18, 2009
Loading...

Share This Page