Date: Sun, 3 Aug 2025 04:49:13 +0100
On Saturday, August 2, 2025, David Brown wrote:
>
>>
> There are microcontrollers supporting C++ with 16-bit pointers where there
> are /no/ invalid pointers - all are valid.
>
I think we should be focusing on this example for a minute.
So let's say we have a Harvard Architecture microcontroller, with code
memory (non-volatile) separate from data memory (volatile), and let's say
it has 65 kilobytes of SRAM.
If address 0 is accessible in the SRAM, then there's three viable
strategies:
(1) Make nullptr == 0xffff
(2) Make nullptr == 0xfffe
(3) Make nullptr == 0x0000, but before any pointer is dereferenced,
subtract 1 from it.
With strategy No. 3, a pointer would have the bit pattern 0x0001 in order
to access address 0.
Next question then is: If you want to identify the last byte as a range,
i.e. [begin,end) , then will the end pointer be the same as the nullptr? If
this must be avoided then it seems like 1 byte in the SRAM must be
inaccessible from the C++ programming language. Unless it were to be
stipulated that the end pointer might be equal to a null pointer.
And then what happens if we introduce badptr? Will badptr be given the bit
pattern 0xFFFF? Subtracting 1 from it would give 0xFFFE -- but maybe that
subtraction should never take place if the operand is 0xFFFF.
>
>>
> There are microcontrollers supporting C++ with 16-bit pointers where there
> are /no/ invalid pointers - all are valid.
>
I think we should be focusing on this example for a minute.
So let's say we have a Harvard Architecture microcontroller, with code
memory (non-volatile) separate from data memory (volatile), and let's say
it has 65 kilobytes of SRAM.
If address 0 is accessible in the SRAM, then there's three viable
strategies:
(1) Make nullptr == 0xffff
(2) Make nullptr == 0xfffe
(3) Make nullptr == 0x0000, but before any pointer is dereferenced,
subtract 1 from it.
With strategy No. 3, a pointer would have the bit pattern 0x0001 in order
to access address 0.
Next question then is: If you want to identify the last byte as a range,
i.e. [begin,end) , then will the end pointer be the same as the nullptr? If
this must be avoided then it seems like 1 byte in the SRAM must be
inaccessible from the C++ programming language. Unless it were to be
stipulated that the end pointer might be equal to a null pointer.
And then what happens if we introduce badptr? Will badptr be given the bit
pattern 0xFFFF? Subtracting 1 from it would give 0xFFFE -- but maybe that
subtraction should never take place if the operand is 0xFFFF.
Received on 2025-08-03 03:49:15