Posted by germanrabbit 2 days ago
It seems to be a vector of bits? Except in practice, a bitvector is just an int where you're using the binary digits to store stuff? And you gotta use these awkward bitwise operators to actually use it? (Popular in 90s video games, to save RAM!)
Or was it another way of saying "ultimately it's the same pattern of ones and zeroes so you can do whatever you want with it as long as you know what you're doing" ?
Exactly. Much equivocation happens when talking about concepts and representation of those concepts. Numbers, bitvectors, pointers, ones-and-zeros, colors, characters, indices, enum values, and whatever all share the same representation. The author thought "bitvector" best represented the commonality (though it doesn't).
Depending upon the architecture, not all values can be memory addresses (aka pointers) due to alignment constraints. Then other way around is possible as long as memory addresses have at least l the same number of bits as integers.
Finally, as long as you don't dereference an integer used (casted) as a pointer, there is no difference. Like equality comparison.
To oversimplify, provenance is the metadata a compiler keeps about a pointer during the compilation process.
On a MTE enabled system, adding an offset to a pointer cast to integer will result in an exception with high probability since the new pointer will be using the tag for the old address.
https://docs.kernel.org/arch/arm64/memory-tagging-extension....
call __printf_chk@PLT mov ecx, DWORD PTR 0[rbp] mov rdx, rbp mov edi, 2 mov DWORD PTR -96[rbx], 7
C and C++ happen to have a particularly restrictive view on what “the semantics” of a program really are, such that there are a lot of things you can write in syntactically-legal C that officially erase the semantic meaning of the code. Within that definition of the program’s semantics, gcc’s optimizer is not supposed to change them, and any such change would be a bug. You’re taking a more expansive view of program semantics than the actual language specifies. If you do that, then any optimizing compiler is going to consider it to be acceptable to violate your special bespoke definition of them.
If that's true, you have a bad language.
What is known to be the case with C, but this is not a desirable nor a necessary state of affairs. A language can and should have defined semantics.
Yes, I'm a C programmer, how did you know?
The language only guarantees that an integer is at least 16 bits. There is no guarantee that a compiler that supports a > 16 bit address space will chose to make integers large enough to hold a pointer, and for example gcc still uses 32-bit integers for 64-bit processors.
I'm not sure if C even requires a pointer to be just a linear address, as opposed to something structured.
Using a tool doesn't mean understanding that tool, just means you know how to follow some repetitive processes over and over again.
I say "almost" because I am not absolutely certain that this is true of absolutely every architecture. Feel free to point out one that breaks these rules, if there is one.