3 ms·
> remembers buffers' size Where? Once you have a bare pointer, you've lost track of what the original definition might have been, so you (the compiler / runti
by pjc50 3y ago
> remembers buffers' size
Where?
Once you have a bare pointer, you've lost track of what the original definition might have been, so you (the compiler / runtime / programmer) have no way of knowing that you've exceeded the size.
- astrange 3y agoThat's not true, it is merely true on most ABIs. The only case where C really erases this information is casting to uintptr_t and back.
- Gibbon1 3y agogcc also has some builtins to check pointer sizes when the compiler is able to figure it out. https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Object-Size-Checking.html https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Object-Size-Che... Which is why I harp on the idea that the real problem is the gold bricks on WG14 who are intentionally blocking improvements to make C safer. Also point out that if you can implement C on 16bit 0x86's segmented architecture you can certainly implement C with phat pointers too.
- pjmlp 3y agoUnless it is clearly specified on the ISO C standard, it is true in practice, and something that is impossible to rely on.