Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sometimes pointer arithmetic is the best implementation; are you implying that C++ would be better off without access to this feature?


The D language dynamic array, which is a pointer+length pair, has (over time) nearly completely supplanted pointer arithmetic. The pair prevents buffer overflows and underflows.

Raw pointer arithmetic is not allowed in code marked @safe.

I've proposed it for C and C++:

https://www.digitalmars.com/articles/C-biggest-mistake.html

It would be simple to add it, and would be legacy compatible.


I very rarely find a use for pointers anymore. Often a whole program has none at all, not even unique_ptr<>. When I do use them, they are front-and-center enough to make mistakes unlikely.


I also rarely use them, but sometimes pointers (via virtual methods and factories) can reduce compile times a lot for components with a stable API but high complexity and churn of the internals. Do you have another way to handle that?


I tend to rely on member unique_ptr for such concerns. At top level, you still don't see any pointers. Of course at machine level the code is absolutely lousy with pointers, likewise at the next level up, but the pointers you can't see because they are buried in libraries cannot generate bugs.


I surmised it would be less complex.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: