How can this possibly work?!
BlitzMax Forums/BlitzMax Programming/How can this possibly work?!
| ||
Local t:Byte Ptr = MemAlloc(1024) t[0] = 100 t[1027] = 10 Print t[1027] Again, its referencing outside of whats allocated. And it doesn't give any warnings in debug. A pointer just points to the first block of memory of a certain size, an array just points to the first element right? So I'm indexing the pointer, so shouldnt t[1027] be out of bounds? |
| ||
T has no 'maximum size' or bounds, you're using array indexing as a memory offset (it is a real pointer). Not a very elegant practicle, spetially in managed languages as BlitzMax. It can even be dangerous if you modify anynithing. |
| ||
I think it's for the same reason given to you 10 months ago here . |
| ||
I thought it was something like that. But how come debug wont warn you about it at least. I'm sure Visual Studio would. |
| ||
No, Visual Studio (in which I presume you mean the VC++ runtime libraries) won't warn you either. (although there are 3rd party bounds checking systems available). The issue with using a pointer is that you as the programmer are responsible to know what you are pointing at and how much of that memory is valid. |