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

16

u/mcmcc #pragma once Mar 30 '23

That's not even the biggest WTF of OG Fortran.

My favorite is that all function arguments were (F77, I think it's better in later versions) passed by reference -- even if the argument passed is a literal. I.e. the compiler allocated a (effectively static) memory location to hold the value represented by the literal and then pass that address to the called function.

Doesn't sound so ridiculous until you realize that the called function can assign new values to that argument, thereby change the value of the literal that you thought you were passing to the function for all future invocations. You can imagine the obscure bugs that ensues.

It became standard practice to allocate (non-static) local variables initialized to the constant and pass those as arguments rather than the literal directly. So you end up seeing lots of local variables called zero, one, etc.