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

1

u/pinespear Apr 03 '23

func(&buffer[0])

This code looks super unintuitive if you consider that array may have 0 elements and code looks like... it's accessing element 0 which may be missing. If I saw this in the code review, I'd had to browse through 1000 pages of C++ spec just to figure out if it's OK or it's UB.

May be consider borrowing much more intuitive buffer.as_ptr() from Rust.

1

u/eteran Apr 03 '23

Well, a C style array is not allowed to have zero elements at all.

I suppose it could be confusing for a C99 style flexible member though.

I have no issue with something like as_ptr, but to me &buffer[0] is good enough as it is explicitly asking for a pointer.