r/AskProgramming • u/SitEnee • May 31 '26
C/C++ Need help with choosing C++ compiler (beginner)
Hi guys. I'm new to C++ (it's a second day). I have experience in Python (I would say I'm kinda good). What is throwing me off, is how errors are explained in compiler (i use no IDE, just vs code with plugins, and GCC compiler in terminal). It's soooo ass (comparing to python at least)! So my question is, should I switch compiler to sum else, or just learn how to handle GCC (I really dunno how other compliers are compared to this one)? Also, I kinda skipped the theory learining process. I was reading some written course, but assumed that programming language is programming language, and if I just raw dog it, I'll get it (so far so good, but it's probably not optimal approach). So, as an addition, do you know any sites that have exercises, with minimal knowledge provided, for each exercise (equivalent to OverTheWire Natas but for C++)? The website must be free tho (I'm kinda broke as sh*t rn).
Sorry for how long and chaotic this came out to be xd
4
u/Shoddy_Law_8531 May 31 '26
I recommend Visual Studio for an IDE if you are on Windows. Compiler errors can be quite cryptic, this is I think an acceptable use of chatGPT, just paste the error to the AI and it will explain what's wrong in plain English... Especially once you start using templates errors are going to be even worse
2
u/Conscious_Ad_7131 May 31 '26
Yeah C++ simply is not friendly as Python, it’s like a billion years old
1
u/Puzzleheaded_Study17 May 31 '26
Just wait until you start working with templates
1
u/james_pic Jun 01 '26
More often than not, the compiler you use is more-or-less dictated by circumstance. There are probably only 1 or 2 reasonable choices of compiler to use for any given platform, and if you're working in a team, you're going to be using whatever platform the rest of the team is using. And in truth, they're all much of a muchness.
If you're not working on a team, and you've got enough choice that you're not tied to a particular compiler, maybe you've got enough choice that you're not tied to C++? Rust is famous, amongst other things, for its clear and helpful error messages, and is often used for many of the same things C++ is used for.
1
u/mredding Jun 04 '26
A common complaint. You'll find that Python makes a lot of decisions for you (encoded into the language itself), and C++ tries not to make any decision for you it doesn't have to. With such leeway comes a burden of responsibility. The C++ compiler doesn't know why your code is failing (why you wrote your code wrong), but it can tell you precisely how, where, and what. This is great for systems engineering, it's unforgiving for application development.
The problem comes from templates, because the standard library wasn't written to be friendly, it was written to be portable and efficient.
Templates aren't "real". Beyond initial parsing into the Abstract Syntax Tree, they don't make it into object code unless instantiated. You have to instantiate a complete template. Often we do this implicitly, so it happens when the compiler first comes across it -
std::vector<int> data;, now anstd::vector<int>has to be realized, and all the template and AST and code generation machinery is invoked.What the errors are trying to tell you is there was a problem in the instantiation process. The template was built in a way expecting something, and that something isn't there or malformed. The compiler will tell you all the things it tried to resolve the issue - usually trying implicit conversions and substitutions to different types based on promotion rules, ADL, and Koenig lookup, and then where, deep down, in what template, that the failure occurred.
So most of the noise is just information - you learn to scan through it quickly and find the error statement that actually tells you what specifically failed, and then your growing C++ expertise will inform you of how to read it and deduce what was wrong.
For example, an
std::maprelies on a defaultstd::less<>to compare keys, which assumes the key type has anoperator <oroperator <=>overload. If you make a key typefoowithout this, you'll get an error telling you this, but it might be a lot of noise before you realize that. At the very least, with the error output and a decent reference, a little familiarity, you have enough information to WORK IT OUT.You DON'T get comparison between types for free - and that's a GOOD thing, because you have a lot of direct control over type semantics, and we have a philosophy of not paying for things we don't use. An implicit comparison between objects means machine code that has to be generated, even if you're not using it. That's exploitable, that's bloat, that's a cost you weren't asking for. So you have to opt in. C++ has one of the strongest static type systems in the industry, but you have to opt in to get the benefits. C++ gets easy once you learn how to work WITH it - it almost dictates HOW to write good code. Most of our peers never learn it, and brute force C With Classes enough to just get the job done.
GCC is sort of the gold standard, so get used to it. The other compilers are all just about the same.
Maybe look into linters, as they parse the code with a compiler front end, and give you feedback in terms of a curated library of opinions.
Yeah, that's cooking you alive, and similar to but unlike the frog in the pot of water, you skipped the wherewithal to have known that. You could have been self-aware, but right now you don't even know how hard you're working. So your "so far so good" take is from the one and only position you know - brute force.
The theory of computation doesn't care about read-time, write-time, or execute-time; the theory of computation doesn't care about software or hardware. Computation is reduced to a single mathematical operation - discreet state changes.
You're thinking of programming languages as machine code generators, when they're really propositional logic systems, the compilers are the theorem solvers, and the programs are the proofs. This is the Curry-Howard correspondence.
Languages give you utilities and properties above the machine code; most of that utility never makes it INTO the machine code, but it guides its generation. It's not just about catching bugs earlier, it's about optimization, equivalence, safety, portability, and semantics. Different languages give you different utilities to affect greater outcomes in one place or another.