Date: Wed, 29 Jan 2025 14:17:58 +0100
Ok, a realistic example:
On an imagined architecture, addresses can be automatically multiplied by a power-of-two factor, when dereferencing.
And postincrementing and decrementing variables by 1 (but not by 8) can be done as part of another instruction.
Then a C++ implementation could decide to store (double*) as the address divided by 8.
Post-increment and decrement would be just a change by 1 and the factor 8 is 2 ^3.
Whenever this pointer is converted to (void*) its address is multiplied by 8 (leftshifted by 3).
If (void*) is converted back to (double*) the address is divided by 8.
The roundtrip from double* to void* to double* keeps the pointer value intact.
But only, if it is aligned correctly.
With this example I show, which freedoms implementers have, that those freedoms could be beneficial on certain architectures in regards to performance and code size.
There has to be a good reason to take away that freedom and also to lower C++ unto a level, which would have been implementation details up till now.
Perhaps the same (what you want) can be achieved with higher-level tools or interfaces provided into the language.
Received on 2025-01-29 13:21:36