468,170 Members | 2,185 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

Cannot allocate array

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?
Aug 1 '08 #1
2 1478
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.
Aug 1 '08 #2
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.

Aug 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Richard Cavell | last post: by
3 posts views Thread by Simon | last post: by
12 posts views Thread by paul | last post: by
3 posts views Thread by Samant.Trupti | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.