C++ Logo

std-discussion

Advanced search

Re: Hostile implementation of strict total order of pointers

From: David Brown <david.brown_at_[hidden]>
Date: Sun, 23 Jul 2023 19:00:55 +0200
On 23/07/2023 17:15, Richard Hodges via Std-Discussion wrote:
> In the light of the C++ memory model being specified in terms of a
> virtual machine, it seems an anomaly to me that the memory model is not
> also specified in terms of a linear address space.
>
> In this model, segmentation would be merely an implementation detail.
> This would remove an enormous amount of unnecessary confusion from the
> language.
>
> If people wanted to work in terms of small segments or paged program
> memory, that is surely something that should be covered by compiler
> extensions, no?
>

There are real systems that don't have a single linear address space.
They are arguably somewhat niche, but real nonetheless. The AVR
microcontroller, for example, has separate address spaces for ram and
for flash. Accessing flash data requires extra effort (typically
compiler builtins, or extra keywords). But it means that you can have
two independent objects whose addresses, when converted to uintptr_t,
are the same number - but which are not the same object. An ordering of
addresses across memory spaces is meaningless.

I don't think it is a good idea to the standards say that all addresses
are in a single linear space, and then say that some compilers have an
extension countering that rule.

Received on 2023-07-23 17:01:14