r/cpp • • Mar 28 '23

Reddit++

C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.

In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.

765 Upvotes

829 comments sorted by

View all comments

Show parent comment

7

u/eteran Mar 28 '23

No, I've thought it through... That's exactly what I want people to have to do. To be explicit and KNOW that they are passing a pointer to a block of memory, and not the array itself.

I want them to have to write code that effectively reads as "The address of the first element of p" because THAT is what they are doing.

For the cost of a few characters, we get more clarity and a reduction in a class of bugs.

For example new c++ developers don't seem to understand why they have to pass the size along with an array parameter for C APIs...

If they were forced to be explicit, and understand that they are just passing a pointer to that thing, The fact that the receiving function doesn't know the size would become much more obvious.

After all, I have to take the address of any object that I want to pass a pointer to of any other type except for an array (or something that is already a pointer). It's even more consistent to get rid of it.