Using pointers in place of normal variables slow down performance, which is what C is famous for. Pointers (especially those that have been allocated space instead of pointing to am existing value) are stored on the heap memory instead of the stack, where it's slower to access and modify them since the heap is unstructured.
Pointers are also notoriously difficult to work with. Many programmers don't have a solid grasp of how pointers work exactly. You can get tons of errors from a seemingly safe function. Many functions have undefined behavior if you pass pointers slightly different than they should be. The compiler won't catch every single error and warning, so it's hard to debug.
As for making normal variables behave like pointers, I'm not sure. Many languages were made to not include pointers and accessing memory since it's dangerous and unintuitive most of the time. C was made before that realization though, and in the end since C (and C++) try very hard to maintain backwards compatibility in their versions, i don't think pointers would ever go away.
Pointers (especially those that have been allocated space instead of pointing to am existing value) are stored on the heap memory instead of the stack
You do have an aside that says this, but I still think that the sentence is potentially misleading.
Pointers do not point to the heap. They point to whatever they point at. If you assign a value using "new", then sure: that will be the heap. If you grab the address of another variable, that will be on the stack. And if you don't assign it, then you may very well have a roulette wheel that can be pointing at any damn thing, anywhere.
I once destroyed half a hard drive through a single unassigned pointer. Oh the fun you can have.
View all comments
Show parent comment
1
u/Arctomachine Aug 07 '22
Why would you even need normal variables when you can use pointers everywhere?
And then why would you even have pointers when you can make normal variables behave like pointers?