Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fwar

Oh OK this is sad

This topic is 6953 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

Yeah, I found that if I make a for loop, I can look at the negative array indexes (or whatever), like array[-345]. It''s just the compiler or C, and will eventually screw you over.



Yeah, I could learn on my own, but I like complaining to ya'll better.

Share this post


Link to post
Share on other sites
Advertisement
an array declared as such:

int MyArray[20];

declares an array of 20 elements, the first being
MyArray[0]
and the last being
MyArray[19]
However, it is possible in some statement to do
MyArray[24] = 7;
This is because C performs no bounds checking on arrays, it is not illegal to the compiler, but it is illegal to the OS, memory, and any programmer you would care to ask.
Stated differently, it is incorrect to access an array element out of bounds and it will cause a crash.

-Mezz

Share this post


Link to post
Share on other sites
You can actually do some pretty neat stuff with arrays because the bounds aren''t checked. For example, say youwould really like your array indicies to go from -10 to 10... no problem!

int myArray[21];
myArray += 10;

Done! Now the valid bounds of your array go from -10 to 10 (inclusive.) Pretty cool, huh?

Check out the GPI project today!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!