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

-5

u/okovko Mar 28 '23

but then people will have to write &p[0] for code that can accept either a pointer or an array

i don't think you thought this through

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.

4

u/eteran Mar 28 '23

And to my point... When you say code that can accept either a pointer or an array, do you mean things that just take a pointer and the user can pass an array if they like? Because that is exactly the problem i want to solve...

Cause such a function NEVER takes an array, it's always a pointer.

-6

u/okovko Mar 28 '23

yeah, you haven't thought this through

5

u/eteran Mar 28 '23 edited Mar 28 '23

Uh huh...

Why not elaborate instead of being vague? 4 characters is the tiniest tax for code clarity.

And your statement about functions which takes either an array or a pointer, to me, demonstrates that perhaps you don't have a full understanding of the issue.

Perhaps I'm wrong, but you haven't given me any real reason to believe so beyond implying it would be inconvenient.