This is out of bounds of the array but , can take negative values because does not deglared as unsigned so negative can be stored.
So my for is from -3 to 54 loop fills correct my walls.
The problem is not of my walls.
My dungeon crawlling engine is working perfect , even I put negative values in my walls. (Out bounds of my levels array , but in fact
is from minus infinity to plus 55 are my limits of my array.
|
Ok. I will put this in as simple english as I can.
Yes, you can use a negative number and store a value in it like you are doing. And Yes this will store the value, and Yes you can read it back later. But
NO you cannot ensure now that your application will not crash randomly,
NO you do not know what memory you have just over-written. Be it another variable, function address, return address, stack pointer.
While you can load into -3 etc fine. Chances are you are over-writing another section of memory that is causing the fread() to crash.
Look at it like this
int array[4];
My stack looks like
1 2 3 4 5 6 7 8 9
|
unknown // If I used array[-2]
unknown // If I used array[-1]
array[0]
array[1]
array[2]
array[3]
unknown // If I used array [4]
unknown
unknown
|
So you can assign outside of the bounds. Shit, I could go
1 2
|
int array[1];
array[939393] = 10;
|
It'd let me, but chances are it would crash. And that's bad programming, and clearly illustrates no knowledge of arrays.
You clear do not have a basic grasp on arrays and data storage in C++. If you want to make up indexes for your arrays. I would try another language that will give you either A) a compiler error when you try such a stupid mistake or B) allow you to have crap indexes without risk. C++ is neither of those languages.
I have provided you with links on the basics of Arrays. Read it.
We have tried to help you solve your problem. But clearly you do not want any help from us, as you are ignoring it and proclaiming your code is valid. When it is not. Even IF you find a way around the crash you experience now, you will have many more crashes because of the invalid memory writes you are performing.