How long will C++ be around?

Started by
72 comments, last by xeyedmary 7 years, 3 months ago

I think I said it rigth: `(c++)' is an rvalue, and the outer ++ attempts to modify it, which is not allowed.


I tried it in Visual Studio and it gave me an error saying, "expression must be a modifiable lvalue". Kind of makes sense if you think about it. The "++" is modifying the value to the left. Unless the 'l' means something else.


An "lvalue" means a value that you could find to the left of an equal sign. You should only use ++ on lvalues, but in (c++)++ you are using it on an rvalue, which is an error. Is it clear now?
Advertisement
Well durr! What was I smoking, of course it Wouldn't work!

Looking at the expression *(ptr++) where ptr is some pointer. ptr++ increments the pointer, but returns the contents (prior to the increment) which is dereferenced with the *.

If (c++)++ was for some reason or another an actual valid operation, *(ptr++) would behave like a *(++ptr) operation, and not how it is supposed to - since ptr++ would have to return ptr, but would only be able to do so after ptr had been incremented.

You could however create a class C and overload the operator = to return the object and not the value, and then do something like ((C=5)=6), but that is some shoddy programming.

Also, can you overload the ++ and += operators?
We could always call it ++C++, then when it's finished nobody can be sure what would happen :D

We could always call it ++C++, then when it's finished nobody can be sure what would happen :D

Only if the comma is a part of the language name, since it creates a sequence point and the result is whatever comes next.

Stephen M. Webb
Professional Free Software Developer

I think the final name is still being debated (quite heatedly last I checked). There are 2 primary groups with diametrically opposed views - one group wants to call it "c+=2" and the other group wants to call it "(c++)++". It's gotten pretty violent...


I don't think those are good names. "(c++)++" is not even valid code, because the outer ++ attempts to modify an rvalue. "c+=2" is better, but it returns the value after the addition, which is not a good parallel to the old C++, where C was increased in some way, but we were given the old value.

But fear not, lambda expressions to the rescue:

[](int &x) { auto r = x; x += 2; return r; }(c)
Now, that's a name we can all get behind.

Hilarious!

This topic is closed to new replies.

Advertisement