Remix.run Logo
mlmonkey a day ago

Whenever I'm dealing with C++, I get tripped by the most basic of things: like for example, why use "&&" for what appears to be a pointer to a pointer? And if this indeed the case, why is int&& x compatible with int& y ?? Make up your mind: is it a pointer to a pointer, or a pointer to an int?!?

I have steadfastly avoided dealing with C++ for almost 30 years, and I am grateful that I did not have to. It seems like such a messy language with overloaded operators and symbols ( don't even get me started on Lambdas!)

TinkersW a day ago | parent | next [-]

If you had read like even the basic part of that article you would know that && is not a pointer to a pointer.

Anyway C++ isn't as complicated as people say, most of the so called complexity exists for a reason, so if you understand the reasoning it tends to make logical sense.

You can also mostly just stick to the core subset of the language, and only use the more obscure stuff when it is actually needed(which isn't that often, but I'm glad it exists when I need it). And move semantics is not hard to understand IMO.

pizza234 a day ago | parent | next [-]

> Anyway C++ isn't as complicated as people say, most of the so called complexity exists for a reason, so if you understand the reasoning it tends to make logical sense.

I think there was a comment on HN by Walter Bright, saying that at some point, C++ became too complex to be fully understood by a single person.

> You can also mostly just stick to the core subset of the language

This works well for tightly controlled codebases (e.g. Quake by Carmack), but I'm not sure how this work in general, especially when project owners change over time.

mlmonkey a day ago | parent | prev | next [-]

> If you had read like even the basic part of that article you would know that && is not a pointer to a pointer.

OK, let me ask this: what is "&&" ? Is it a boolean AND ? Where in that article is it explained what "&&" is, other than just handwaving, saying "it's an rvalue".

For someone who's used to seeing "&" as an "address of" operator (or, a pointer), why wouldn't "&&" mean "address of pointer" ?

throwaway150 a day ago | parent [-]

Your comments are very confusing.

> For someone who's used to seeing "&" as an "address of" operator (or, a pointer)

You must be talking about "&something" which takes the "address of something" but the OP does not talk about this at all. You know this because you wrote in your other comment ...

> And if this indeed the case, why is int&& x compatible with int& y ?

So you clearly understand the OP is discussing "int&&" and "int&". Those are totally different from "&something". Even a cursory reading of the OP should tell you these are references, not the "address of something" that you're probably more familiar with.

One is rvalue reference and the other is lvalue reference and I agree that the article could have explained it better what they mean. But the OP doesn't seem to be an introductory piece. It's clearly aimed at intermediate to advanced C++ developers. What I find confusing is that you're mixing up something specific like "int&&" with "&something", which are entirely different concepts.

I mean when have you ever seen "int&" to be "address of" or "pointer"? You have only seen "&something" and "int*" and "int**" be "address of" or "pointer", haven't you?

djmips a day ago | parent | prev [-]

Unless, you work with a large team of astronauts who ignore the coding guidelines that say to stick with a core subset but leadership doesn't reign them in and eventually you end up with a grotesque tower of babel with untold horrors that even experienced coders will be sickened by.

wocram a day ago | parent | prev | next [-]

&& is not a pointer to a pointer, it's a temporary value. There is a huge amount of cognitive overhead in normal cpp usage because over time we have found that many of the default behaviors are wrong.

thw_9a83c a day ago | parent | prev | next [-]

> Whenever I'm dealing with C++, I get tripped by...

Problem: Whenever I'm dealing with X, I get tripped by Y.

Solution A: Don't deal with X.

Solution B: Understand Y, when dealing with X.

For && meaning, this article [1] is still very useful.

[1]: https://isocpp.org/blog/2012/11/universal-references-in-c11-...

einpoklum a day ago | parent | prev [-]

> "Whenever I'm dealing with C++" ... "I have steadfastly avoided dealing with C++"

So, basically, you're just trolling us about a language you avoid using. Thanks, that's very helpful.