C++ Logo


Advanced search

Re: [ub] Justification for < not being a total order on pointers?

From: Ion Gaztaņaga <igaztanaga_at_[hidden]>
Date: Fri, 18 Oct 2013 18:29:22 +0200
El 17/10/2013 0:27, Stephan T. Lavavej escribiķ:
> Separately, I believe that the Core Language should simply recognize
> the fact that all machines these days have a flat memory model.
> (Two's complement and 8-bit bytes would be nice too.)

I program for modern architectures where CHAR_BIT is 32 or 16, mainly
DSPs. Examples:

- Analog Devices (Tiger)Sharc family
- Texas Instruments TMS family


See official documentation for the modern TigerSharc family:


Data Types and Data Type Sizes

Type / Word Size (Bits) / Result of sizeof operator

char, signed char,unsigned char / 32 / 1
short, unsigned short / 32 / 1
int, unsigned int / 32 / 1
long, unsigned long / 32 / 1
pointer / 32 / 1


Maybe we can require CHAR_BIT to be power of two but not exactly 8 bits.

One's complement/Sign magnitude or non-power of two CHAR_BIT are
available only in emulated machines to support legacy code (but those
could just use C90/C++03). No idea about segmented architectures,
though. However, since since [u]intptr_t are optional and they only

void *orig_addr = ...
uintptr_t uinted_ptr = (uintptr_t)orig_addr;
assert( ((void*)(uinted_ptr)) == orig_addr);

Then we maybe need an new type that guarantees a total order when
converted from a pointer (e.g. in segmented architectures, conversion
would require taking the address of the segment register and adding the
offset stored in the pointer). Then std::less<T*> could be implemented as:

bool operator()(const T &l, const T &r)
{ return unique_address_ptr_t(l) < unique_address_ptr_t(r); }

Another option is to make uintptr_t mandatory and require total order
when two unrelated object addresses are converted to uintptr_t.



Received on 2013-10-18 18:29:43