Jump to content
  • Advertisement
Sign in to follow this  
Craig M

Invalid use of array with unspecified bounds (probably something obvious)

This topic is 4689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Argh. I just know I'm missing something obvious here, but I cant for the life of me think of what it is. Here is the code in question: void ClearMap(int mizzap[][]){ int r,c; for(r = 0; r < ROWS; r++) { for(c = 0; c < COLS; c++) { mizzap [r][c] = 0; <-- The compiler targets this line } } } Dev C++ throws this: 28 D:\Dev-Cpp\Tilemap\MapEdit.c invalid use of array with unspecified bounds This is floating right above my head, and any help would be much appreciated!

Share this post


Link to post
Share on other sites
Advertisement
My compiler targets this line
void ClearMap(int mizzap[][]){ // <-- here

with this error '<Unknown>' : missing subscript

Since the second array is not known going into the function, it would not know what size to increment when you do indexing.

Share this post


Link to post
Share on other sites
When you pass an array like this (int mizzap[][]) the compiler basically passes only a pointer to the first entry. The size is not passed on.

But if you want to access a second dimension of an multi-array you need to know the count of the first dimension. The compiler complains that it doesn't know this size. You have to either access the array 1-dimensional (Index = c * ROWS + r) or change that specific function to use something like memset:

memset( mizzap, 0, sizeof( int ) * ROWS * COLS );

Be careful that you should use memset only if you have basic data types (not classes with virtual functions e.g.).

Share this post


Link to post
Share on other sites
Can't you do:
void ClearMap(int mizzap[5][]);
or is it:
void ClearMap(int mizzap[][5]);

where 5 is the actual number. I try and avoid 2D arrays so not 100% sure which is correct.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike2343
Can't you do:
void ClearMap(int mizzap[5][]);
or is it:
void ClearMap(int mizzap[][5]);

where 5 is the actual number. I try and avoid 2D arrays so not 100% sure which is correct.


Second one. The first array dimension is optional. All dimensions after that are required.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!