Live data from Hacker News

C++ Cheat Sheets

hackingcpp.com

31–40 of 82 posts

Re: C++ Cheat Sheets

#31

Earlier quoted context omitted.

* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf

This is all solid advice (particularly using a faster linker). IME, the single best way to reduce your C++ compile times is to compile less code : * Remove all unnecessary headers. Template expansion is slow, and preprocessing is even slower. Some of the standard includes (like ` ` and ` `) are notorious for slowing individual translation units to a crawl. `#pragma once` for your own headers also helps with cpp-time…

Constexpr improves compilation speed by the degree that it displaces template metaprogramming. Template metaprogramming runs at Python speed, where constexpr runs orders of magnitude faster. Anywhere you have a choice between them, choose constexpr.

Substantial improvement in compilation speed might depend on use of JIT techniques, running generated code in the compiler to perform template evaluation. I.e., a template is not just a data structure, it is a compile-time function that, where used much, is compiled to optimized machine code, its run-time values being what we think of as types. Thus far, all these functions are run like an interpreter walking a syntax tree.

Precompiled headers, or module intermediate files, could have this code in them already optimized.

Re: C++ Cheat Sheets

#32
post #2

Wow, this is really good, there are still things I can learn. C++ really has a lot of good things. It's just a shame it's so slow to compile. I'm curious if anybody is working to make C++ faster to compile. Even if it was a subset of the language, with some features removed, it would be good enough for me.

* Compile with clang, link with mold or at least lld. mold can link gigabyte-sized binaries in, like, one second * Use ninja instead of make * Use PCH * -gsplit-dwarf

Is clang still faster? I thought it had slowed down in the past decade and was now worse than GCC.

Re: C++ Cheat Sheets

#33

Probably semi related, but when I was looking at C/C++ job offers, why are they paid so little in comparison to Python or JavaScript? It seems like C/C++ is much more complex. I was mainly looking at embedded stuff vs Web. For example senior C++ role was paying £45k pa on average and over £60k for JS.

If it says "C/C++", it means they don't even know what they want, and might even be satisfied with a cave-dwelling C coder.

The highest-paid programming jobs are mainly held by C++ programmers, many of them in service of financial gambling. That work shades over into FPGA and HPC programming at the high end. A skilled C++ programmer at these shops can get a half $million, some more.

Re: C++ Cheat Sheets

#34
post #6

Earlier quoted context omitted.

Microsoft Visual Studio for Windows and QtCreator for Linux.

I find visual studio to be absolutely horrendous for C++. Refactoring doesn't work (even a simple rename symbol!) The errors aren't accurate, autocomplete seems to suggest every symbol from the stdlib before the class defined in the file itself and can't tell when it should suggest classes vs functions/variables. Oh and of course compile errors are absolutely useless but I suppose that's a C++ thing in general. The e…

Compile errors will anyway be getting better as concept support gets built out.

Re: C++ Cheat Sheets

#35
Cheat sheets are so incredibly useful.

All documentation would be so much better if it came with cheatsheets you could quickly scan for things that you might need.

I wonder why they are so rare...

Re: C++ Cheat Sheets

#39
post #33

Probably semi related, but when I was looking at C/C++ job offers, why are they paid so little in comparison to Python or JavaScript? It seems like C/C++ is much more complex. I was mainly looking at embedded stuff vs Web. For example senior C++ role was paying £45k pa on average and over £60k for JS.

If it says "C/C++", it means they don't even know what they want, and might even be satisfied with a cave-dwelling C coder. The highest-paid programming jobs are mainly held by C++ programmers, many of them in service of financial gambling. That work shades over into FPGA and HPC programming at the high end. A skilled C++ programmer at these shops can get a half $million, some more.

Yeah, job adverts (and resumes) with "C/C++" usually seem like they are reading off MS VisualStudio marketing and imo a clown indicator. I've seen this with jobs which were really C# or Java (or maybe even VB). Top C++ programmers are highly compensated and only unemployed when they want to be.
Post reply on HN