Shouldn't invalid references like this fail at compile time?
Mike Franklin
slavo5150 at yahoo.com
Thu Jan 25 04:01:47 UTC 2018
On Thursday, 25 January 2018 at 02:41:53 UTC, Walter Bright wrote:
>
> Ok, but are these devices with 0 being a valid address?
>
> It seems weird to me that any sane modern CPU design that can
> access megabytes of memory would have 0 be a valid address.
Yes, 0 is a valid address and typically points to ROM
(http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIJJE.html).
"The initial stack pointer and the address of the reset handler
must be located at 0x0 and 0x4 respectively."
(http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIJJE.html)
So you read address 0, dereference it, and you're at the bottom
of the stack.
Some microcontrollers have an MPU to mitigate this. You can read
one technique here:
http://nuttx.org/doku.php?id=wiki:howtos:stm32-null-pointer But
the MPU is an optional component, and many microcontrollers in
the ARM Cortex-M family do not have one.
Mike
More information about the Digitalmars-d
mailing list