Quote:
Originally Posted by jbjb
Depends what you're writing - if you're writing highly optimised high-performance code (maybe for DSPs, but not necessarily), or OS kernels, or memory management code (will often happen in userland code, not driver-level), or many other scenarios, address arithmetic is entirely appropriate. C has been successful for a reason! Admittedly it can go horribly wrong, but if you know what you're doing it's very powerful, so you just have to be careful about who you allow to do it. (And horrible, dangerous code can be written in any language - there's no C monopoly on that!).
|
No, it's not ever appropriate ever in ordinary applications. The high level language and compiler does it. Yes, obviously the final program execution does address arithmetic.
See also the stupidity of how strings / array bounds* work in most languages and 40 years after this being identified not just as a way programs crash, but a common security exploit there is still stupid programming.
Never mind the stupidity of Bobby Tables exploits in SQL.
https://m.xkcd.com/327/
If you need to do direct address arithmetic outside of a specialist (likely assembler) device driver, for performance, you have a rubbish compiler.
[* Oh such fun to write a VB6 program calling a DLL passing a string. VB6 strings are mysterious. You first have to assign a maximum length string to the VB variable or the DLL goes BANG! A proper VB string has string size at the -1th position of the array, but C, C++ or Modula-2 doesn't know that.]