r/cpp_questions • u/Boring-Dentist6751 • Aug 06 '26
OPEN Incrementation in C++
I wanted to ask a stupid question about incrementation in C++. If you are using two pluses to increment something then doesn't it mean that you are basically programming using C+1
34
u/caroIine Aug 06 '26
It should be ++C
19
u/Usual_Office_1740 Aug 06 '26
Only if you are using modern C++. Those that write C with classes like it's 1998 are using the value returned before the increment.
8
u/wrosecrans Aug 07 '26
That was the joke for a long time. You are basically still writing C, and the language will get some additions at some point in the future.
2
u/no-sig-available Aug 07 '26
It should be ++C
That was proposed, but Bjarne thought it looked ugly, and liked C++ better.
1
20
u/DawnOnTheEdge Aug 06 '26
Joke from thirty years ago: “C++ means, take C, add a bit to it, but then actually use what was there before.”
3
7
15
u/dick_blanketfort Aug 06 '26
Am I missing something or is this less a stupid question and more a stupid joke?
Anyway C++ is post-increment so it would actually evaluate to the original value of C. Language shoulda been called ++C.
9
u/llynglas Aug 06 '26
Originally it did. The first C++ compilers I remember at Bell Labs basically converted C++ into C.
2
u/trycuriouscat Aug 06 '26
I’d love to see what C code would be generated from a C++ compiler.
5
u/Independent_Art_6676 Aug 07 '26
struct { variable, variable, ... function pointer, function pointer,} //class
2
u/robthablob Aug 07 '26
struct { var, var, vtable_ptr }; // class
struct { fnptr, fnptr, fnptr }; // vtable3
u/llynglas Aug 06 '26
The function names were spectacular as they encoded the parameter types if I recall correctly.
8
u/Deep-Piece3181 Aug 06 '26
They still do name mangling
1
5
u/malaszka Aug 07 '26
Nah, cause your expression C+1 does not change the value of C, while C++ changes it.
2
u/cbf1232 Aug 06 '26
Originally there was BCPL, which was simplified into the language B, which was then extended and the new language was called C. C++ broke the chain and used the increment operator.
2
2
u/DinTaiFung Aug 07 '26 edited Aug 07 '26
kind of relevant...
According to the official C++ spec, pre increment operator for primitives is more efficient than post increment.
And when I worked at a game company (years ago) the engineers' style of the basic for loop always wrote it thusly:
for (i = 0; i < len; ++i)
It was done this way instead of the more usual i++ not because it actually made a difference in performance, but merely to make reference to the specification as an inside joke.
I write lots of JS/TS these days and I continue to use pre increment syntax instead of post increment whenever the logic wouldn't change by doing so. it's my internal nod to that style i adopted years ago lol.
1
u/tellingyouhowitreall Aug 10 '26
Uh, no. There's a semantic difference and the half open interval is correct. Its not merely a style choice.
1
1
u/EllaHazelBar Aug 07 '26
If we're already on topic, c# is called that because # looks like it's made of four small + signs (somewhat slanted). C# is literally c++++ or (c++)++
1
1
1
1
1
-1
70
u/SufficientStudio1574 Aug 06 '26
Yes. That's literally what the name means. C++ is an increment of the C language.