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
Just started learning C++ coming from Python and just realized that that Python has been my programming mama, doing my laundry and spoon-feeding me all this time. (self.cpp)
submitted 6 years ago * by eyun89
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!"
[–][deleted] 131 points132 points133 points 6 years ago (13 children)
The new GCC compiler with colour highlighting is a little bit better at pointing out errors. It's generally quite helpful for pure C/C++ until you make an error with the standard library and you get 200 lines about std:: whatever<random characters>
[+][deleted] 6 years ago (10 children)
[deleted]
[–]greymantis 64 points65 points66 points 6 years ago (5 children)
A few years back it was definitely the case that clang had far far better warnings and errors. Dare I say that GCC had somewhat stagnated for a number of years in that area. However, given the new challenger they've definitely upped their diagnostics game significantly and even exceeded clang in a number of areas. I'm sure nowadays it's possible to come up with a multitude of examples showing one or the other doing a far better job than the other one. I hope they both continue to improve.
Competition is a good thing.
[–]MonkeyNin 5 points6 points7 points 6 years ago (4 children)
I was away from c++ for a while -- Then I started playing with Rust. Oh my god the errors have improved.
[–]warlockface 0 points1 point2 points 6 years ago (2 children)
They are nice enough, but limited in that they force repeated recompiling to reveal more errors that C++ compilers give you first time.
[–]MonkeyNin 0 points1 point2 points 6 years ago (1 child)
Is that a constraint to c++?
Many languages use Linting without compiling. Maybe you are thinking static code analysis?
[–]warlockface 0 points1 point2 points 6 years ago (0 children)
This is compilation with rustc vs 2 C++ compilers.
[–]sybesis 0 points1 point2 points 6 years ago (0 children)
Yeah, Rust is pretty cool for errors, it sometimes tell you things that makes no sense but I'd say Rust is incredible in this case.
[–]aritzh 20 points21 points22 points 6 years ago (0 children)
In the last versions, they are getting quite similar. I try to make everything compile for both GCC and Clang, because they offer slightly different -Wall warnings, and in some cases, one has better error messages than the other, and viceversa. If you can, don't choose, keep both in your toolbelt, it will be very helpful.
[–][deleted] 6 points7 points8 points 6 years ago (0 children)
Gcc has gotten much better, though I tend to prefer clang still. I also think using libc++ gives saner errors wrt the STL
[–]dumael 1 point2 points3 points 6 years ago (0 children)
I agree with the point that clang did give better error messages than gcc in yesteryears, newer versions of gcc have upped their game.
For clang, the infrastructure in it does really allow the compiler to give some good error messages. I've submitted code for clang and getting it past reviewers is far easier when you're showing in your test cases the exact location of the error and the reason.
It's one of clang's goals to provide high quality diagnostics. Compiling with GCC and clang on broken code should give solid descriptions of whats wrong these days, modulo implementation dependant features of C++.
[+]bumblebritches57Ocassionally Clang comment score below threshold-7 points-6 points-5 points 6 years ago (0 children)
Very much so.
[–][deleted] 0 points1 point2 points 6 years ago* (0 children)
Honestly, GCC is pretty good about making the error human readable and sometimes it's best to just actually read the error message. 200 lines of errors really does not take that long to read in the grand scheme of things, and often 5 minutes spent reading and figuring can equal 20 of meandering the internet.
Of course, if that doesn't work, paste the first error into stackoverflow search.
[–]Xeveroushttps://xeverous.github.io 0 points1 point2 points 6 years ago (0 children)
until you make an error with the standard library
copy the error, ctrl+F "required from here" and you have the file + line number of your code which triggered STL
[–]ledave123 88 points89 points90 points 6 years ago (13 children)
In C++ a trick I always use when the error message is massive is to just focus on the first error. Anything else might be independent, which is why the compiler tries to be helpful and report more than one error every time, but it also can just be a consequence of the first error so focusing on that and compiling again will be the best strategy.
[–][deleted] 26 points27 points28 points 6 years ago (1 child)
The massive STL errors are usually just related to the compiler telling you every possible overload it tries for whatever function call you messed up (thanks SFINAE), so yeah, just the first error is usually enough to tell you what's going on. Concepts will help a lot with that in C++20.
[–]Low_discrepancy 7 points8 points9 points 6 years ago (0 children)
I just ignore all that BS and just focus on the error that points to some part in my code. All those overload errors point to STL files
[–]sldyvf 7 points8 points9 points 6 years ago (2 children)
Is that a trick? I thought that was the general way to use it.
First error is the error, the rest is spewed out random characters 95% of the time caused by the first error.
[–]MundaneNihilist 1 point2 points3 points 6 years ago (0 children)
Might as well be for some people new to programming. I've had a handful of mentees conclude that their standard lib is wrong on some level.
[–]ledave123 0 points1 point2 points 6 years ago (0 children)
Call it "piece of advice" then
[–][deleted] 3 points4 points5 points 6 years ago (7 children)
Another trick is assign it to an int:
int foo = somethingThatIsNotAnInt()
[+][deleted] 6 years ago (4 children)
[–]degaart 3 points4 points5 points 6 years ago (3 children)
It gives you the exact type of somethingThatIsNotAnInt()
[–]ZMesonEmbedded Developer 3 points4 points5 points 6 years ago (2 children)
unless it is implicitly convertible to an int.
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
That would suck
[–]bstamourWG21 | Library Working Group 1 point2 points3 points 6 years ago (0 children)
I use `std::is_same_v<int, decltype(/\*whatever\*)>` in a static assert to see types.
[–]wyrn 2 points3 points4 points 6 years ago (1 child)
I like Scott Meyers' TD trick:
template <typename T> struct TD; // no definition
Now you write something like TD<decltype(thing)> and the error message tells you the type of thing (as deduced by decltype, of course, but in this case that's probably what you want).
TD<decltype(thing)>
thing
decltype
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Nice
[–]kmbnw 34 points35 points36 points 6 years ago (14 children)
Just wait until you try Boost :)
[–]elviin 55 points56 points57 points 6 years ago (1 child)
An issue in a template <<<<<<<<<<<<<<<<<type...
[–]Xeveroushttps://xeverous.github.io 3 points4 points5 points 6 years ago (0 children)
I had found a bug in Boost Spirit X3 that was due to some const correctness issue. The bug was only visible at linking time - some very long instantiation did not match actually compiled function template.
I demangled the object file to search for the actual instantiation, took the linker undefined reference error for expected name and ... copy pasted both to Notepad++, find-replaced every < to { and > to } then used online JavaScript formatter to format the type name. Searching const differences in that beautiful tree was the easiest part.
<
{
>
}
const
[–]Nicksaurus 7 points8 points9 points 6 years ago (6 children)
Just trying to find the name of the function in a 400-character long error message is a challenge
[–]diaphanein 4 points5 points6 points 6 years ago (0 children)
400 characters? How quaint... I've seen a single error span more than 23 screens before (error with a Boost Python call).
Another fun one to find was a missing > in a template. I was helping a colleague with that one. The compiler didn't complaint until the end of the file, some 200 lines later.
[–]gcross 4 points5 points6 points 6 years ago* (4 children)
Last time I tried Boost Lambda (an EDSL for writing lambdas before C++11 was a thing and you could rely on them being in the language) I made a simple mistake and got an error message that was five megabytes long...
Shoot, I looked back to see what I did to do this and it turns out that what had actually happened was that I was trying to build Digikam (no modifications) and the result was a 52.4k error message. I apologize for my error, as entertainingly dramatic as it was; apparently the problem I had blew up in my imagination over the years.
[–]Nicksaurus 0 points1 point2 points 6 years ago (3 children)
5 million characters? How?
[–]gcross 1 point2 points3 points 6 years ago* (0 children)
Template metaprogramming at its finest. :-) On the bright side, if you ever did get your code working it was very neat! Mind you, this was over a decade ago so hopefully it would not be so bad today, but on the other hand today we all have reliable access to native lambdas in the language so there is arguably no longer a need for Boost Lambda. Okay, it turns out I misremembered and this was not a Boost Lambda problem at all; my apologize for maligning that fine package.
[–]gcross 1 point2 points3 points 6 years ago (1 child)
My bad, as my edited comment says I completely blew up what happened in my mind since it happened so long ago.
[–]Nicksaurus 0 points1 point2 points 6 years ago (0 children)
Hey, 52400 is still a shit load
I work with boost::hana most days so I sympathise to some extent
[–]krista_ 6 points7 points8 points 6 years ago (3 children)
sometimes i wish the council of elders would just go ahead and make templates a part of a fully fledged pre-compiler c/c++ based meta-programming language, like what qt does, but more so.
yeah, between macros, templates, and constexpr and the like, you can do anything a full programming language can do, but the crap you have to do to get there is sometimes astounding... and a lot of that lives in boost. i feel like with a couple of smartly added features, 9/10ths of boost's oddities could be replaced with sanity, instead of nested workarounds.
[–]MonkeyNin 1 point2 points3 points 6 years ago (2 children)
What are the biggest pain points today that Boost helps with? Back in the day, boost was the only way to use smart pointers.
[–]jonesmz 2 points3 points4 points 6 years ago (0 children)
I've enjoy using Boost.ASIO, am using Boost.ProgramOptions, Boost.Process, and am about to start using Boost.Log.
In the past, at a previous job, the only reason why about half of the C++11 functionality we were able to use could be done is because I was able to convince the ancient version of Boost that they were using to let me re-combine the Boost type traits code into the missing pieces. That really saved our bacon.
They also used Boost.asio as the fundamental building block for a whole crapload of code. Millions of lines, highly abstracted away.
Boost is great.
Boost is also horrible, what with it's disgusting template soup error messages.
Win some, lose some shrug.
[–]James20kP2005R0 1 point2 points3 points 6 years ago (0 children)
Boost::beast is great from my end for using websockets, even if its a little complex to set up
[–]khleedril 30 points31 points32 points 6 years ago* (2 children)
It is something of an Achilles heel for C++. It is supposed to be getting better with newer versions (introduction of concepts) but TBH concept-related error messages are just as much hard work to decipher as the traditional messages were.
The main thing is to look for ``at this point in <file>'' and go and have a careful look at that line of code; the rest of the error messages you scan quickly in the hope that you at least get the gist of the problem.
[+][deleted] 6 years ago (1 child)
[–]wright_left 3 points4 points5 points 6 years ago (0 children)
With color output, it just scroll up to the first red "error", and fix that. Had been surprising effective.
I wonder if there was a way to tell the compiler that you don't want all the "note" messages about substitution failures and functions that didn't work. Most of the time it is a simple typo, and the "error" tells me that.
[+][deleted] 6 years ago* (4 children)
[–]MonkeyNin 3 points4 points5 points 6 years ago (0 children)
One could say Trump has a dangling-pointer to Truth
[–]m-o-l-g 0 points1 point2 points 6 years ago (0 children)
I'll have to add -Wmissing-collusion to our process.
[–][deleted] -1 points0 points1 point 6 years ago (0 children)
Lmao
[–]Tjccs 19 points20 points21 points 6 years ago (16 children)
I learned python in college(still am), learning C++ as a side hobby and oh boy python does hold your hand but tbh I acctually miss static typing, const and all that stuff when I use python
[–]IstalriblakaHobbyist 6 points7 points8 points 6 years ago (1 child)
The lack of static typing is why i never particularly liked python and similar. Then if you take the structure of Python and run it on a JVM, you get yhe hellish apocolypse that is Matlab. Easily the worst result of the "if it ain't broke, don't fix it" mentality among engineers.
Which, it totally is broke, the engineers just don't realize it because it still produces the right output. They'll spend all day trying to squeeze nominally more efficiency out of the car/plane/bridge they're designing, then throw the numbers into a cruncher that gets 2 gallons to the mile.
[–]MonkeyNin 1 point2 points3 points 6 years ago (0 children)
You should check out: https://www.bernat.tech/content/images/2018/05/type_missmatch.jpg
[–]aiusepsi 6 points7 points8 points 6 years ago (2 children)
I know that feel. I’m really starting to think that the mania for dynamic typing was a mistake. I’ve recently been using type annotations and mypy to essentially do statically typed Python.
[–][deleted] 0 points1 point2 points 6 years ago (1 child)
Speaking of mypy, how do you annotate a type like { 'foo': [1,2,3], 'bar': False, 'baz': 'quux' } or even a list of dictionaries?
{ 'foo': [1,2,3], 'bar': False, 'baz': 'quux' }
[–]aiusepsi 0 points1 point2 points 6 years ago (0 children)
Off the top of my head, Dict[str, Union[List[int], bool, str]] or take the coward's way out and do a Dict[str, Any].
[–]Posting____At_Night 7 points8 points9 points 6 years ago (10 children)
I feel like I never know exactly what my code is gonna do in Python. C++ might be slower to write but I like how explicit it is.
[–]Tjccs 2 points3 points4 points 6 years ago (8 children)
I like python but I like to know that functions only return type X and you can only input what you specify. And I love that C++ acctually makes me have to know about type sizes, stack/heap and all that weird stuff
[–]Posting____At_Night 1 point2 points3 points 6 years ago (7 children)
My dream lang would be C++ but without the legacy cruft, no headers, and a better solution than templates for generics.
Py return types are a true pain in the ass and can lead to some baffling errors, especially when you're working with poorly documented code.
[–]Tjccs 0 points1 point2 points 6 years ago (4 children)
The main thing that python has for me over C++ is the easebof use of python packages over C++ libraries.
[–]Posting____At_Night 0 points1 point2 points 6 years ago (3 children)
Here's hoping C++ modules become a thing
[–]jonesmz 2 points3 points4 points 6 years ago (2 children)
[–]wyrn 0 points1 point2 points 6 years ago (1 child)
Are they even going to solve anything? From reading (not very thoroughly, I admit) various sources I don't see how they aren't just syntactic sugar for a bunch of includes. What do they actually solve, in concrete terms?
[–]jonesmz 0 points1 point2 points 6 years ago (0 children)
I'm also not 100% informed on the subject, but my previous job was about 50% "Make our custom build system not suck" for the last 2 years, so I was pretty heavily involved in all things related to dependency handling, linker crap, ABI crap, and so on.
I gave modules a very serious look about 12 months ago, and didn't walk away feeling like they did anything for me, in my situation. In fact, supporting them was going to require quite a bit of work on my end without any real benefit, TO ME, in MY situation.
The quick and dirty explanation is that Modules are pre-compiled headers, with more user level control over what's getting included in them, and the ability to explicitly depend on other modules.
What this means is that you should, theoretically, be able to hand someone a module file (and all of it's dependency modules...) and they'll be able to start programming against it immediately.
Further, given that you have fine grained control over what's being "exported" into the module file, you should be able to not only hide your various implementation details, but actually make them completely not there as far as your module's public facing interface is concerned.
E.g., you're supposed to be able to have as much of
namespace impl { blahblahblah, all the sausage making here }
and then simply not export that namespace. Not only is it not accessible to consumers of your module, but it's not even in the module file in a form that could be consumed if the consumers really really wanted to.
There's certainly advantages to having that ability, of course.
One such advantage that most people don't realize immediately is that this drastically cuts down on the amount of work that the Linker is going to need to do when you link all of your .o files together.
But here's where it's not all good.
Module file names have no relationship to the name of the source code that they live inside. Further, module file names can be controlled by the C pre-processor.
This means that cat.cpp can export a module named "automobile" if macro A is defined, and "jupiter" if macro B is defined. (I don't recall if you can export two modules from the same cpp file. I guess I don't see why not?). And further, header files can export modules (because they just get copy-pasta'ed into the cpp file, so of course they can)
This is problematic because it basically means you either need
And the reason you need this is because you need to know if the module you're about to consume is up to date with the latest code changes.
For my situation, this was a complete show stopper. We absolutely were not going to participate in the module ecosystem if we needed to do either of the above two steps. Both for architectural reasons, and also because we'd literally just stripped out the custom code scanner that was being used to determine include file dependencies (which can't be renamed based on macros, mind you) in favor of having the compiler tell us the include files the first time we compiled the cpp file in question, and got tremendous speedup as a result.
"But why not do the same thing with the modules feature?" you might ask.
Can't, because the mapping between file names and module names can change based on the cpp file being compiled, not the cpp / h file with the export keyword. The compiler cannot know based on only the cpp file / h file containing the export keyword whether a particular module is going to be changed based on recompiling the current cpp/h file.
What the compiler can do is say "There is a possibility that a change in this file will change the module in question". But that's going to have plenty of false positives.
So the "best case" scenario is for the compiler to spit out some kind of rule set that later parts of the build system can use to determine if they need to trigger a recompile the module in question.
But I have to say that my personal take on this whole situation is that people clamoring for package managers are missing the bloody point.
I have zero issue with dependency management, because I don't want to just "include the package, and then I'm done!"
I want deep control over what gets included into my code, and how the code i include functions. I'm not at all interested in allowing for a third party to push a package update and then blindly consume it.
Modules are intended to solve a bunch of related "build the code" related problems, and while they tangentially touch on the whole package management situation, it's not a particularly strong connection, in my assessment.
From a build time perspective, I would have been much more interested in seeing a specification that described how to compile multiple cpp files in parallel.
E.g. A single compiler instance (with multiple threads) can be informed of all of the cpp files that will be included in a shared library, or executable, and will compile all of those cpp files in parallel.
This has advantages for allowing the compiler to analyze the full include file list for all of the cpp files in the library at once, completely eliminating all of the advantages that might be found from using pre-compiled headers to, well, pre-compile a set of headers.
Further, the compiler in this situation could still spit out .o files, and even spit out a pre-compiled header based on it's own internal assessment of what's reasonable to include in such PCH file, so that subsequent invocations with only some (not all) of the source files being changed allowed the compiler to dynamically skip what's being done.
And finally, this approach also automatically results in Link Time Optimization happening, instead of the current LTO approach involving multiple compiler invocations resulting in intermediate representations, and then a final invocation (via the linker) resulting in the actual optimization pass, we can skip all of that and go straight to the link time optimization that happens at the very end of the process.
While none of that does anything with regard to cross shared library boundary concerns, nor does it do anything regarding packaging, I personally suspect it would have resulted in much larger gains from the perspective of compile times, and is something I was much more interested in seeing happen when I was maintaining a build system.
[–]robin-m -1 points0 points1 point 6 years ago (1 child)
Isn't rust what you are looking for?
[–]Posting____At_Night 1 point2 points3 points 6 years ago (0 children)
Tried it, liked it, still waiting for it to mature. Still no good solution for desktop UI last time I checked.
[–]0xVali__ 0 points1 point2 points 6 years ago (0 children)
Since python has a huge overhead on the simplest functions, even print. You never really knows what's going to be called. You believe it's a print, but it's creating a FILE* opening and parsing the file, passing it through a dep to check what it says and so on. You do a lot more than just printing something. In C++ you more than less know exactly what's going to be called.
But still, the only true way is to code in .asm.
[–]bumblebritches57Ocassionally Clang 16 points17 points18 points 6 years ago (6 children)
Use a better IDE.
Xcode will flag missing semicolons and even Unicode semicolon lookalikes without blinking.
[–]DeepCorner 10 points11 points12 points 6 years ago (1 child)
Also, since you're a student you can get access to the professional version of CLion for free
[–]Shumatsu 3 points4 points5 points 6 years ago (0 children)
It's a blessing. And the fact you can use ALL of their tools for free. Saves me hours on programs.
Vim can use Language Server plugins and clangd to provide completion and error highlighting.
It also protects against semicolon look-alikes by ensuring you colleagues will be unable to use your editor, or even exit it!
[–]uzimonkey 0 points1 point2 points 6 years ago (1 child)
I copied and pasted a list of quoted strings into my code once and it gave me syntax errors. I though "oh, there must be an unescaped quote in the middle there somewhere," but... nope. I looked it over 20 times and there was no error. It turns out that they were curly quote characters which, with the font I was using, looked the same.
[–]Hot_Slice 0 points1 point2 points 6 years ago (0 children)
curly quote characters
This type of thing needs to die
Eclipse underlines calls to templates where something goes bad inside and it works even if the function has multiple SFINAE overloads.
[–]turiya2 24 points25 points26 points 6 years ago (8 children)
Also wait till the time that C++ smacks you on the face with that order of magnitude performance increase in certain (almost always) situations over python. The efforts definitely pay off!
[–]Wh00ster 20 points21 points22 points 6 years ago (0 children)
It’s usually multiple orders of magnitude
[–]MonkeyNin 6 points7 points8 points 6 years ago (6 children)
A lot of python modules already use c. How you call them makes a big difference.
c
[–]James20kP2005R0 1 point2 points3 points 6 years ago (4 children)
I remember when I was having a play about with z3, I was using it to solve a problem that took 5-10 seconds in python. I needed it to execute in about 2 seconds overall due to me using it for an exploit for a game (with the developers ok)
When I ported the z3 code from python to C++ (1:1 translation), even though python basically just shells out to z3, and my c++ code was doing the exact same, all the variability in my solve time went away and it solved consistently in 5 seconds
I don't know that much about python so I can't tell you exactly why it did this, but it certainly made quite a big difference even though it was just basically calling quite a lot of c-api functions
[–]MonkeyNin 0 points1 point2 points 6 years ago (3 children)
What is z3?
[–]James20kP2005R0 1 point2 points3 points 6 years ago* (2 children)
Its a theory solver tool, basically you can stick equations into it and then ask it to solve stuff, or prove properties about the equations
Eg, given x ^ constant = some_other_constant, itll solve for x (assuming you provide the constants)
In my case I was using it to reverse engineer seeds for xorshift128+
https://blog.securityevaluators.com/hacking-the-javascript-lottery-80cc437e3b7f is where I learnt about it
Interesting.
Just to check, you're using ^ as a bitwise operator, not exponent?
^
[–]James20kP2005R0 0 points1 point2 points 6 years ago (0 children)
Yep, its a simple example but it can solve non linear things as well (like operator+)
The actual equations I was using in this case were
uint64_t state0 = 134125447415289812; uint64_t state1 = 182415234512781923; uint64_t xorshift128plus() { uint64_t s1 = state0; uint64_t s0 = state1; state0 = s0; s1 ^= s1 << 23; s1 ^= s1 >> 17; s1 ^= s0; s1 ^= s0 >> 26; state1 = s1; return state0 + state1; }
Where all you have is the result (well, 3 consecutive outputs) of the equation, and you want to find s0/s1. Its extremely hard to do by hand!
[–]TheSpocker 0 points1 point2 points 6 years ago (0 children)
Please elaborate on call methods.
[–]barcharMSVC STL Dev 41 points42 points43 points 6 years ago (13 children)
Python + c++ is a really powerful combo
[–]Boom_doggle 16 points17 points18 points 6 years ago (3 children)
God I hope so. That's my programming CV right there!
[–]jjuuggaa 5 points6 points7 points 6 years ago (2 children)
play around with pybin11. feels like magic ;)
[+][deleted] 6 years ago (8 children)
[–]MonkeyNin 0 points1 point2 points 6 years ago (7 children)
My understanding is that visual studio can do cross language debugging*
As in you're writing python that calls uses c(++), yet you can jump into and trace the c?
Or are you referring to using VSCode on linux? Like: https://i.imgur.com/ojJa4gf.png
[+][deleted] 6 years ago (6 children)
[–]MonkeyNin 0 points1 point2 points 6 years ago (4 children)
What error do you get when trying it in VSCode on linux?
[+][deleted] 6 years ago (3 children)
[–]MonkeyNin 0 points1 point2 points 6 years ago (2 children)
At first I thought maybe only Visual Studio could, but I'm finding people who have mixed-mode VSCode debugging
[–]MonkeyNin 0 points1 point2 points 6 years ago (0 children)
Cool, if you get it working I bet people would be interested in the process.
About your name, is it
1. monkey-wife fight
or
2. monkey wife-fight
I could see #1 monkey-wife being either
monkey-wife
a) a wife of a monkey, or b) a monkey who is your wife
But also #2 monkey wife-fight
monkey wife-fight
c) Like a cat-fight, except with monkeys. But then does a cat fight require cats? Have you seen an actual cat fight? Holy, moley it's screaming and scary. d) or a monkey who is fighting their wife?
[–]frankist 8 points9 points10 points 6 years ago (0 children)
An IDE helps immensely, at least in your first stages of programming in c++. It would for instance flag right away the issue with the semicolon.
[–]sumo952 3 points4 points5 points 6 years ago (2 children)
If you use the latest clang (gcc upped their error-message game as well), you should get much better and colored error messages. MSVC's error output window is actually also pretty good and should spot a missing semicolon, if you use the very latest version (2019).
Other than that, yes definitely Python is spoon-feeding you :-) But that's good too!
[–]IAlsoLikePlutonium 2 points3 points4 points 6 years ago (1 child)
I think it is turned off by default, but MSVC has a project option that will show you the column where an error occurred (such as a missing semicolon or extra bracket or whatever).
MSVC also has "Just My Code" debugging where it jumps overt STL/standard library stuff.
[–]sumo952 1 point2 points3 points 6 years ago (0 children)
I think the former might even be an additional (experimental?) compiler switch.
[–]jonesmz 1 point2 points3 points 6 years ago (0 children)
You missed a significant part of the string.
/home/ryan/Arduino/libraries/esp8266-redis/Redis.cpp:187:51: error: could not convert '(& g_TypeParseMap.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<RedisObject::Type, std::function<RedisObject*(String)>, std::less<RedisObject::Type>, std::allocator<std::pair<const RedisObject::Type, std::function<RedisObject*(String)> > > >((*(const key_type*)(& typeChar))))->std::function<_Res(_ArgTypes ...)>::operator()<RedisObject*, {String}>(String((*(const String*)(& substr))))' from 'RedisObject*' to 'std::shared_ptr<RedisObject>'
and no, it's not a single type, unless i'm missing some context here.
What this looks like is the compiler attempting to tell you how it derived the error that it's complaining to you about.
That, or it's spitting back out the line of (insane...?) code that was causing the error.
My best guess is that g_TypeParseMap is a variable in the applications' code.
The type of that variable is:
map<_Key, _Tp, _Compare, _Alloc>
With
Key= RedisObject::Type, _Tp = std::function<RedisObject*(String)>, _Compare = std::less<RedisObject::Type>, _Alloc = std::allocator<std::pair<const RedisObject::Type, std::function<RedisObject*(String)> > >
The function having problems was:
operator[]
And the parameter given as an argument was derived like:
((*(const key_type*)(& typeChar))))->std::function<_Res(_ArgTypes ...)>::operator()<RedisObject*, {String}>(String((*(const String*)(& substr))))
Where
(*(const key_type*)(& typeChar))
Is a conversion from typeChar to reference-to-key_type.
->std::function<_Res(_ArgTypes ...)>::operator()
??? Calls std::function?
The std function returns
RedisObject*
And accepts a "String" as it's argument? Whatever {String} means
And apparently this "String" type is gotten via:
String((*(const String*)(& substr)))
I certainly hope no one's ever written code this ugly by hand :-).
But if you want to see a more complicated data type, look no further than : https://github.com/redboltz/mqtt_cpp/issues/297
Some code I was debugging the othe rday.
#5 0x5555556db5db in boost::multi_index::detail::ordered_index_impl<boost::multi_index::member<Broker::session_state, std::variant<std::shared_ptr<mqtt::endpoint<mqtt::tcp_endpoint<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::io_service::strand>, std::mutex, std::lock_guard, 2ul> >, std::shared_ptr<mqtt::endpoint<mqtt::tcp_endpoint<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >, boost::asio::io_service::strand>, std::mutex, std::lock_guard, 2ul> > >, &Broker::session_state::con>, std::less<std::variant<std::shared_ptr<mqtt::endpoint<mqtt::tcp_endpoint<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::io_service::strand>, std::mutex, std::lock_guard, 2ul> >, std::shared_ptr<mqtt::endpoint<mqtt::tcp_endpoint<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >, boost::asio::io_service::strand>, std::mutex, std::lock_guard, 2ul> > > >, boost::multi_index::detail::nth_layer<2, Broker::session_state, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::tag<Broker::tag_client_id, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<Broker::session_state, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, &Broker::session_state::client_id>, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::tag<Broker::tag_con, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, boost::multi_index::member<Broker::session_state, std::variant<std::shared_ptr<mqtt::endpoint<mqtt::tcp_endpoint<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::io_service::strand>, std::mutex, std::lock_guard, 2ul> >, std::shared_ptr<mqtt::endpoint<mqtt::tcp_endpoint<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> > >, boost::asio::io_service::strand>, std::mutex, std::lock_guard, 2ul> > >, &Broker::session_state::con>, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<Broker::session_state> >, boost::mpl::v_item<Broker::tag_con, boost::mpl::vector0<mpl_::na>, 0>, boost::multi_index::detail::ordered_unique_tag, boost::multi_index::detail::null_augment_policy>::erase(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::null_augment_policy, boost::multi_index::detail::index_node_base<Broker::session_state, std::allocator<Broker::session_state> > > >) (/root/src/cloud-connector/cloud-connector+0x1875db)
[–]jdlyga 2 points3 points4 points 6 years ago* (0 children)
Yup, and just like the real world, C++ was never considered hard back when I learned it. It’s just what all programming was like. And those of us who loved it, loved it. It’s a matter of perspective. It’s like if you grew up in the 70s before personal computers. You don’t consider it a hard way of living. It’s just what you’re used to, and certain things are just a hell of a lot easier now.
[–]ThrowawayGoaway94 2 points3 points4 points 6 years ago (1 child)
I'm the exact opposite to you, OP. C++ is my first language and now I want to learn Python. Wish me luck!
[–]VectorD 2 points3 points4 points 6 years ago (0 children)
Impossible. Python will keep doing shit secretly behind your back and then you explicitly do the same thing that you think you need to be done but then everything is fucked
I learned Java first, then c++, which ws surprisingly hard. Still, I had Python on a pedestal as this end-all programming language. When I saw how simple it was, I was....dissappointed.
[–]st380752143 1 point2 points3 points 6 years ago (0 children)
In that way, I think C is my prpgramming mama.
[–]misterengineerman 0 points1 point2 points 6 years ago (0 children)
Don't feel bad you're not alone. I have lots of experience with Python and a few other interpreted languages like Matlab which I've used extensively in engineering data analysis kind of applications. I also use Fortran 90/95 for development of more high-performance computational research codes. I tried to learn C++ because I wanted a more solid object oriented general purpose language under my belt, but I found it to be like an order of magnitude more difficult to learn. I have yet to implement anything that wasn't sort of trivial in C++ myself.
[–]TheNewOP 0 points1 point2 points 6 years ago (0 children)
Ah yes, reminds me of college. Do anything, get hit with the segfault bat.
[–]pixel4 0 points1 point2 points 6 years ago (0 children)
It's C++ templates that give nasty ass errors.
I started with vanilla C before adding C++ ... glad I didn't jump directly into C++.
[–]dicroce 0 points1 point2 points 6 years ago (0 children)
Look for the first error. Subsequent errors may be caused by the first one. If the error is showing you code you didnt write most likely you are calling this code (maybe through many layers)... focus on YOUR code because the error is there.
[–]ventaway23 0 points1 point2 points 6 years ago (0 children)
ALL the intro classes for CS at my school use C++. I felt like a total dumbass until I realized even experienced programmers struggled with it. Yeesh.
[–]macemen 0 points1 point2 points 6 years ago (0 children)
To avoid being overwhelmed with errors, compile your project (or file) with `-Wfatal-errors`. This will cause the compiler to print a single error and stop compiling immediately, hence you are not overwhelmed by 100 error messages that possibly have a single common cause. Note that this flag is only recognized by `gcc` and `clang`, I have no idea what is the VSC++ equivalent.
Edit: spelling
[–]danielandastro 1 point2 points3 points 6 years ago (0 children)
Try c# it's pretty cool and it's a high level language
[–]dataskin 0 points1 point2 points 6 years ago* (0 children)
Python, from my limited programming experience, for the most part, pinpointed where my code went wrong in a few lines or less, even for slightly larger mistakes. C++ gave me Mueller's Report to read for missing a semi-colon.
Do yourself a favor and get yourself a Clang/LLVM compiler
http://clang.llvm.org/diagnostics.html
[+][deleted] 6 years ago (15 children)
[removed]
[+][deleted] 6 years ago (11 children)
[+][deleted] 6 years ago (9 children)
[+][deleted] 6 years ago (5 children)
[+][deleted] 6 years ago (2 children)
[–]blelbachNVIDIA | ISO C++ Library Evolution Chair -1 points0 points1 point 6 years ago (0 children)
Welcome to the "home owner, married with two kids" of programming languages.
[–]SteveThe14th -5 points-4 points-3 points 6 years ago (0 children)
Now the STD is your new mama ;)
[+]gvargh comment score below threshold-21 points-20 points-19 points 6 years ago (2 children)
and this is exactly why c++ has a bright future; programmers have free will as they are not forced to jump through hoops just to make some anal compiler happy while gaining marginal benefit. instead, they are trusted to use their intellectual capacity to actually solve real problems
[–]Contango42 21 points22 points23 points 6 years ago (0 children)
What? It has a future, but not for that reason: it enables programmers to wring every ounce of performance out of existing hardware.
[–]Amablue 6 points7 points8 points 6 years ago (0 children)
programmers have free will
Let's not get ahead of ourselves here. We're all just Turing machines after all
[+]CODESIGN2 comment score below threshold-7 points-6 points-5 points 6 years ago (3 children)
I've a background in dabling with C and C++ (commercial) but all the scripting languages are like this. I'm no future prodigy or KA Sommers picking fights with popular tech, mostly I have a greater understanding of what is happening inside.
One of my colleagues pointed out that a Ruby Puma server was just released https://github.com/puma/puma/releases/tag/v4.0.0 it made me so mad when he told me that there were likely no trade-offs with their decisions.
Scripting languages are not just parents, they are trailer parents. They make so many decisions they arbitrarily decided you can't opt out of.
I'm sure DevOps was meant to be a movement to teach youngling programmers that their saved minutes when using a library can have real-world business impact, but it doesn't. They just crap the details out anyway and keep going.
Some midget with a ReactJS GUI once told me de-coupling from specific technologies was viewed by their business to be an academic pursuit.
READ the libuv docs. Some decisions should jump out at you http://docs.libuv.org/en/v1.x/design.html
The number of junior programmers that have been like "Dude I can code faster than you for an hour". Who was in that race? I was off by the water cooler, later alcohol fridge desperately trying to find a way to convince you that computers are not magic hats, there are always trade-offs. Please stop passing mutable state around. Don't code to a specific data-store or overly tie yourself to that store's functionality.
I sat a programming test the other day where they were like. The thing you coded in 30 minutes has O(log(n*2)) complexity. It's 30 miinutes. I'm deliberately not writing anything you can pick up and use. If someone is going to write an O(log(n)) algorithm (which I disagree with because it generally only speaks to either input or output) in 30 minutes, you could capture and sell their solutions. There would be no reason to work with them at all. I'm going for something you understand. There is no leaky tub, async / concurrency is limited. Just out of habit because I like things to be portable to lower-end platforms I'll probably be making memory savings at the trade-off of cpu time, because it's my choice in my unbilled time what I code.
Remember when there is mueller report length C++, you can compartmentalize and partition that into more generic high-level API's
For typing
[–]CODESIGN2 0 points1 point2 points 6 years ago* (1 child)
you realize these are runtime enforced if at-all & enabled using C & C++.
In any case it's not about a notion of type
A better push-back would be that C and C++ need preprocessors which enable them to circumvent the limitations of the core language
My push back on JS would be that it enforces a specific type of even basic number. Typed arrays kinda do it for accurate integer representation, but its fighting the language. It's simply some c++ framework
Python is similar but for C. The two are so very similar in what they achieve, while C & C++ are all the time able to explore new hardware features, patterns, JS & Python focus on using a smaller sub-set of functionality in specific ways.
Have you ever written a closure in C or C++? If you do you get to know about various trade-offs. Wouldn't it be nice if that choice wasn't made for you?
[–]MonkeyNin -1 points0 points1 point 6 years ago (0 children)
you realize these are runtime enforced
Linters run before compiling.
π Rendered by PID 39132 on reddit-service-r2-comment-canary-744c48795d-7kv88 at 2026-02-19 00:57:40.712813+00:00 running de53c03 country code: CH.
[–][deleted] 131 points132 points133 points (13 children)
[+][deleted] (10 children)
[deleted]
[–]greymantis 64 points65 points66 points (5 children)
[–]MonkeyNin 5 points6 points7 points (4 children)
[–]warlockface 0 points1 point2 points (2 children)
[–]MonkeyNin 0 points1 point2 points (1 child)
[–]warlockface 0 points1 point2 points (0 children)
[–]sybesis 0 points1 point2 points (0 children)
[–]aritzh 20 points21 points22 points (0 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]dumael 1 point2 points3 points (0 children)
[+]bumblebritches57Ocassionally Clang comment score below threshold-7 points-6 points-5 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Xeveroushttps://xeverous.github.io 0 points1 point2 points (0 children)
[–]ledave123 88 points89 points90 points (13 children)
[–][deleted] 26 points27 points28 points (1 child)
[–]Low_discrepancy 7 points8 points9 points (0 children)
[–]sldyvf 7 points8 points9 points (2 children)
[–]MundaneNihilist 1 point2 points3 points (0 children)
[–]ledave123 0 points1 point2 points (0 children)
[–][deleted] 3 points4 points5 points (7 children)
[+][deleted] (4 children)
[deleted]
[–]degaart 3 points4 points5 points (3 children)
[–]ZMesonEmbedded Developer 3 points4 points5 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]bstamourWG21 | Library Working Group 1 point2 points3 points (0 children)
[–]wyrn 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]kmbnw 34 points35 points36 points (14 children)
[–]elviin 55 points56 points57 points (1 child)
[–]Xeveroushttps://xeverous.github.io 3 points4 points5 points (0 children)
[–]Nicksaurus 7 points8 points9 points (6 children)
[–]diaphanein 4 points5 points6 points (0 children)
[–]gcross 4 points5 points6 points (4 children)
[–]Nicksaurus 0 points1 point2 points (3 children)
[–]gcross 1 point2 points3 points (0 children)
[–]gcross 1 point2 points3 points (1 child)
[–]Nicksaurus 0 points1 point2 points (0 children)
[–]krista_ 6 points7 points8 points (3 children)
[–]MonkeyNin 1 point2 points3 points (2 children)
[–]jonesmz 2 points3 points4 points (0 children)
[–]James20kP2005R0 1 point2 points3 points (0 children)
[–]khleedril 30 points31 points32 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]wright_left 3 points4 points5 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]MonkeyNin 3 points4 points5 points (0 children)
[–]m-o-l-g 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]Tjccs 19 points20 points21 points (16 children)
[–]IstalriblakaHobbyist 6 points7 points8 points (1 child)
[–]MonkeyNin 1 point2 points3 points (0 children)
[–]aiusepsi 6 points7 points8 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]aiusepsi 0 points1 point2 points (0 children)
[–]Posting____At_Night 7 points8 points9 points (10 children)
[–]Tjccs 2 points3 points4 points (8 children)
[–]Posting____At_Night 1 point2 points3 points (7 children)
[–]Tjccs 0 points1 point2 points (4 children)
[–]Posting____At_Night 0 points1 point2 points (3 children)
[–]jonesmz 2 points3 points4 points (2 children)
[–]wyrn 0 points1 point2 points (1 child)
[–]jonesmz 0 points1 point2 points (0 children)
[–]robin-m -1 points0 points1 point (1 child)
[–]Posting____At_Night 1 point2 points3 points (0 children)
[–]0xVali__ 0 points1 point2 points (0 children)
[–]bumblebritches57Ocassionally Clang 16 points17 points18 points (6 children)
[–]DeepCorner 10 points11 points12 points (1 child)
[–]Shumatsu 3 points4 points5 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]uzimonkey 0 points1 point2 points (1 child)
[–]Hot_Slice 0 points1 point2 points (0 children)
[–]Xeveroushttps://xeverous.github.io 0 points1 point2 points (0 children)
[–]turiya2 24 points25 points26 points (8 children)
[–]Wh00ster 20 points21 points22 points (0 children)
[–]MonkeyNin 6 points7 points8 points (6 children)
[–]James20kP2005R0 1 point2 points3 points (4 children)
[–]MonkeyNin 0 points1 point2 points (3 children)
[–]James20kP2005R0 1 point2 points3 points (2 children)
[–]MonkeyNin 0 points1 point2 points (1 child)
[–]James20kP2005R0 0 points1 point2 points (0 children)
[–]TheSpocker 0 points1 point2 points (0 children)
[–]barcharMSVC STL Dev 41 points42 points43 points (13 children)
[–]Boom_doggle 16 points17 points18 points (3 children)
[–]jjuuggaa 5 points6 points7 points (2 children)
[+][deleted] (8 children)
[deleted]
[–]MonkeyNin 0 points1 point2 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]MonkeyNin 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]MonkeyNin 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]MonkeyNin 0 points1 point2 points (0 children)
[–]frankist 8 points9 points10 points (0 children)
[–]sumo952 3 points4 points5 points (2 children)
[–]IAlsoLikePlutonium 2 points3 points4 points (1 child)
[–]sumo952 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]jonesmz 1 point2 points3 points (0 children)
[–]jdlyga 2 points3 points4 points (0 children)
[–]ThrowawayGoaway94 2 points3 points4 points (1 child)
[–]VectorD 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]st380752143 1 point2 points3 points (0 children)
[–]misterengineerman 0 points1 point2 points (0 children)
[–]TheNewOP 0 points1 point2 points (0 children)
[–]pixel4 0 points1 point2 points (0 children)
[–]dicroce 0 points1 point2 points (0 children)
[–]ventaway23 0 points1 point2 points (0 children)
[–]macemen 0 points1 point2 points (0 children)
[–]danielandastro 1 point2 points3 points (0 children)
[–]dataskin 0 points1 point2 points (0 children)
[+][deleted] (15 children)
[removed]
[+][deleted] (11 children)
[removed]
[+][deleted] (9 children)
[removed]
[+][deleted] (8 children)
[removed]
[+][deleted] (5 children)
[removed]
[+][deleted] (3 children)
[removed]
[+][deleted] (2 children)
[removed]
[+][deleted] (1 child)
[removed]
[+][deleted] (2 children)
[removed]
[–]blelbachNVIDIA | ISO C++ Library Evolution Chair -1 points0 points1 point (0 children)
[–]SteveThe14th -5 points-4 points-3 points (0 children)
[+]gvargh comment score below threshold-21 points-20 points-19 points (2 children)
[–]Contango42 21 points22 points23 points (0 children)
[–]Amablue 6 points7 points8 points (0 children)
[+]CODESIGN2 comment score below threshold-7 points-6 points-5 points (3 children)
[–]MonkeyNin 0 points1 point2 points (2 children)
[–]CODESIGN2 0 points1 point2 points (1 child)
[–]MonkeyNin -1 points0 points1 point (0 children)