Quote:Original post by SpoonbenderQuote:Original post by Washu
Yes, pointing a pointer outside of the bounds defined (that is the start to one past the end) is undefined. No dereferencing required. Imagine a segmented system.
Just curious here, but what *would* happen in a segmented system?
Assuming you've used a segmented memory system before: Imagine what would happen when dealing with the difference between a long pointer and a short one. Think about the behavior of moving the pointer to before the block of memory it points to. Depending on pointer casts that may/may not be present, this could actually result in a[n] NOT being anywhere near your array. This is but one example. Other examples that come to mind: Some embedded systems actually have address registers that have some limited validation semantics associated with them. Specifically, certain blocks of addresses are reserved and cannot be pointed to. In those cases that subtraction trick can result in your pointer ending up in one of those regions, which would result in a hardware exception (that would have to be caught and handled by the RTOS).