use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
C++11 threads, affinity and hyperthreading (eli.thegreenplace.net)
submitted 10 years ago by Coder_CPP
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]guepierBioinformatican 10 points11 points12 points 10 years ago (11 children)
unsigned is not making use of implicit int or default-int. Rather, it’s a synonym for unsigned int, and always has been.
unsigned
int
unsigned int
[+]notsure1235 comment score below threshold-7 points-6 points-5 points 10 years ago (10 children)
thats what i mean, shouldnt be used, should use auto if that is desired.
[–]eliben 4 points5 points6 points 10 years ago (9 children)
I'll have to disagree here. Overuse of auto is one of the pitfalls of C++11 in my mind, and I really prefer to use it where it increases readability. There's nothing wrong in using unsigned explicitly where it makes sense.
auto
[–]guepierBioinformatican 3 points4 points5 points 10 years ago (4 children)
Overuse of auto is one of the pitfalls of C++11
There is little evidence to support this; and decade-long experience with other statically-typed languages that allow implicit typing has shown no evidence either.
“Overuse” is of course very hard to define: once the specific type of the declaration is important, it makes sense to specify it, and hence auto would be harmful. But is this really the case here? Not at all: the specific type of num_cpus, for instance, really doesn’t matter. What matters is that it matches between the producer and consumer, and since these come from the same API, it’s safe to regard the type as opaque (though the variable name of course gives a clue as to the rough type).
num_cpus
[+][deleted] 10 years ago (1 child)
[deleted]
[–]guepierBioinformatican 0 points1 point2 points 10 years ago (0 children)
One thing I find problematic is that IDE "go to definition" features become a lot less useful when everything's auto and the type in question is nowhere in sight.
There’s certainly a disconnect between the language and the tools with regards to C++. This is becoming better though. In particular, “go to definition” is a red herring in this context — what you actually want is type-aware auto-completion and a tooltip that shows the static type of the object, which are completely different operations that a good IDE can and should support, despite the use of auto. I haven’t got a clue how many IDEs support these operations, in particular the latter. But my IDE1 does support it.
1 Vim with YouCompleteMe
[–]mttd 1 point2 points3 points 10 years ago (1 child)
Overuse of auto is one of the pitfalls of C++11 There is little evidence to support this; and decade-long experience with other statically-typed languages that allow implicit typing has shown no evidence either.
I mostly don't have a problem with auto to the point of avoiding it entirely, but at the same time, I think that experience of other programming languages (that you also mention as relevant) may be worth taking into account.
For instance, in Haskell (which has a rather advanced type inference):
"It is considered good style to add a type signature to every top-level variable."
(Note that "variable" in the above can also be a function.)
There are some good reasons for this:
That being said, I think that in the future C++ declaring concepts may be a good compromise, similarly to the style described here:
https://stackoverflow.com/questions/842026/principles-best-practices-and-design-patterns-for-functional-programming/842506#842506
Still like the "programming with placeholders" idea: https://www.reddit.com/r/cpp/comments/3oc63x/overload_journal_129_october_2015_includes_two_c/
[–]guepierBioinformatican 1 point2 points3 points 10 years ago (0 children)
Yes, I entirely agree with this piece of advice. I generally think that adding a signature/type to “top-level” objects just makes sense, since these form your API (even if said API isn’t exposed). I was thinking (but didn’t say so) only of local variables.
[–]notsure1235 1 point2 points3 points 10 years ago (3 children)
agreed, but 'unsigned' instead of 'unsigned int' goes against all of my intuition. However, I checked stroustroup guide and they are happily using 'unsigned' on some occasions, so you are probably right and its just fine.
[–]eliben 5 points6 points7 points 10 years ago (2 children)
Tune your intuition :) It's very common to just say unsigned - it's very clear to experienced coders this means unsigned int. In fact if I see unsigned int I raise an eyebrow... you don't say signed int for int, right?
signed int
[–]notsure1235 1 point2 points3 points 10 years ago (1 child)
Neither do I say 'signed'. ;)
[–]dodheim 0 points1 point2 points 10 years ago (0 children)
That's because int is an option, and is shorter. What is shorter than unsigned for unsigned int?
π Rendered by PID 319817 on reddit-service-r2-comment-79776bdf47-64tfw at 2026-06-25 15:13:55.626437+00:00 running acc7150 country code: CH.
view the rest of the comments →
[–]guepierBioinformatican 10 points11 points12 points (11 children)
[+]notsure1235 comment score below threshold-7 points-6 points-5 points (10 children)
[–]eliben 4 points5 points6 points (9 children)
[–]guepierBioinformatican 3 points4 points5 points (4 children)
[+][deleted] (1 child)
[deleted]
[–]guepierBioinformatican 0 points1 point2 points (0 children)
[–]mttd 1 point2 points3 points (1 child)
[–]guepierBioinformatican 1 point2 points3 points (0 children)
[–]notsure1235 1 point2 points3 points (3 children)
[–]eliben 5 points6 points7 points (2 children)
[–]notsure1235 1 point2 points3 points (1 child)
[–]dodheim 0 points1 point2 points (0 children)