If I have a int* pointer for example, that points to the start of an int array and step through the array until I get the value 123, is it defined in D what happens if you step off the end of the array?

What I might expect to happen is for the code to just keep stepping through sequential memory locations until it finds one that happens to have a 123 in it, until it gets a memory protection fault of some kind, or failing that wrap around memory and go into an infinite loop.

The options are really
1) I can rely on the compiler consistently doing what I'd "expect" on a specific platform.
2) There is some other defined behaviour
3) The compiler can do whatever crazy thing it feels like as this is considered broken code.

I'm not for a moment suggesting this is a good idea, but what I'm really asking is does the D language say anything about this? C++ seems to have chosen (3). Personally I'd prefer (1) but it's most to know if the "standard" such as it is has anything to say on such matters.

Reply via email to