3 ms·
There is no problem with static initializations with a null pointer that is not all zero bits, or a floating-point 0.0 that is not all zero bits. Those values
by kazinator 4y ago
There is no problem with static initializations with a null pointer that is not all zero bits, or a floating-point 0.0 that is not all zero bits.
Those values just cannot participate in the "BSS" trick, whereby everything that is zero-initialized is put into a special section that doesn't actually exist in the program image, and is only provided on startup.
Those values would go into the initialized data section.
The problem with 0.0 or null pointers not being all zero bits is all the code that uses calloc or memset zero.
If this is on some specialized platform (e.g. DSP chip), it might not matter that vast quantities of C code are not portable.
In general, compiler (and to a great extent instruction set architecture!) designers are quite hamstrung by the expectations of C programmers and programs; that has been the situation for some thirty years now.
Today, you could not sucessfully introduce a system in which pointers to bytes (void , char ) have a different representation from other pointers (let alone different size, lord forbid).
- pjmlp 4y agoIf we if ignore ongoing efforts on hardware memory tagging since SPARC ADI.
- kazinator 4y agoHardware memory tagging schemes carefully avoid breaking common C idioms. What breaks are - truly dubious programs which use pointers in ways they really shouldn't, and are almost certainly just bugs; like use-after-free. When a pointer with an out-of-date tag is passed to the library, that is pretty much a confirmed use-after-free, which is not a legitimate idiom of non-maximally-portable C, like assuming that all pointers are the same size. - C programs which manipulate the pointer representation: e.g. run-times for dynamic languages that put their own tags in pointers. These can easily work around tagging. (I've dealt with this on Android recently, quite easily. For the affected objects, I strip the tag away, and work with the untagged pointers. When it's time to pass the pointer back to Android's library, I put the tag back. All other code works as before.
- pjmlp 4y agoYeah, but all of that falls off ISO C defined semantics.
- mananaysiempre 4y agoIncidentally, AFAICT C23 now allows stashing log2 alignof(max_align_t) bits in pointers in a portable (if awkward) manner: for example, for a char pointer p, the lowest such bit can be retrieved with memalignment(p)<2 and masked off with p-(memalignment(p)<2). (C++’s std::aligned would be less awkward, but, well, memalignment() is what we get.) You still can’t portably store pointers and integers (or doubles) in the same place and distinguish them, though.