3 ms·
> All those code samples will crash and burn if s and t point to the wrong locations This is true for all uses of pointers in C. The only validation you can do
by tom_mellior 5y ago
> All those code samples will crash and burn if s and t point to the wrong locations
This is true for all uses of pointers in C. The only validation you can do is whether a pointer is null. Apart from that you can never know that a pointer points to a non-wrong location. And still experienced C programmers seem to be OK with using pointers.
- pjmlp 5y agoActually no, many OSes do have APIs to validate pointer integrity. But even then, most experienced C programmers don't care about using them anyway, that is why Apple, Oracle, Microsoft, ARM, Google, Cambridge university are all leading efforts for hardware memory tagging. So it won't matter how much they care, as the OS will kill their beloved application when pointers get misused. A scenario already made reality in platforms like Solaris SPARC.
- tom_mellior 5y ago> many OSes Are outside the scope of the C language. But if you allow these special APIs, you can use them to implement a safe strcpy. Either way your point from above is still invalid.