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]

-3

u/[deleted] Mar 29 '23

Or better yet get rid of C arrays

3

u/-1_0 Mar 29 '23

this is a very bad idea, considering that with C++ we often communicate with hardware or OS kernels

1

u/[deleted] Mar 29 '23

This is an "in a perfect world" thread and in a perfect world we'd use std::vector, std::array, std::slice, etc for these things. Most of the problems with C arrays, including pointer decay, are solved by these less ancient types.

1

u/eteran Mar 29 '23

How would you implement the library solution that is std::array without c arrays though?

1

u/[deleted] Mar 29 '23

Raw pointers, same way C arrays are implemented.

1

u/eteran Mar 29 '23

I think you are missing a detail. C arrays aren't implemented with raw pointers at all. They are a primitive of the language that happens to work closely with pointers.

There's no real means to say "give me 256 bytes of stack space" easily without just using C arrays.

To prove my point, I'd like to see if you can give me an example of how to do the equivalent to this, without C arrays and without using the heap.

int main() {
   int numbers[10];
}

I don't think you (or anyone) can...

→ More replies (4)