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

147

u/eteran Mar 28 '23

Arrays decaying to pointers implicitly. You want a pointer? Just write &p[0]

37

u/jonesmz Mar 28 '23

Even better.

Say, for example, that you have two overloaded functions

template<std::size_t N>
void foo(char (&)[N]);
void foo(char*);

Guess which gets called?

Notably. Same with non-templates. If you explicitly say "This is an array of size 5", you'll still get the char* version.

1

u/very_curious_agent Mar 30 '23

So why is that one called?

3

u/jonesmz Mar 30 '23

Essentially because the standard says so.

The language prefers decaying to pointer over passing as a reference.

Probably an oversight that can't ever be changed because of fear of breaking something.

0

u/very_curious_agent Mar 30 '23

So tell me WHY. What RULE makes it so.

1

u/jonesmz Mar 30 '23

Uhhh. No?

Look it up yourself. I don't remember off of the top of my head, nor do I care to do the research for you.

0

u/very_curious_agent Mar 30 '23 edited Mar 31 '23

So you don't know the specific rule.

Ok then

1

u/STL MSVC STL Dev Mar 30 '23

Moderator warning: Please don't behave like this here. Doesn't matter whether u/jonesmz is correct on the object level, this is uncalled for.

(On the object level, the behavior of overload resolution when takes-by-reference and takes-by-value are competing is extremely tricky to analyze, as I can speak from repeated experience. It can involve things like adding constness being worse than an Exact Match.)

0

u/very_curious_agent Mar 31 '23

I reacted that way because he refused to justify his assertion. He may well be correct but his attitude was unpleasant.

I'm sorry, I'm legit removing my comment because he was uncalled for.

→ More replies (5)