2 ms·
A "fun" exercise in C++ is to take a line of code that makes extensive use of advanced features, like templates, smart pointers, etc. and step through a -O0 com
by mv1 15y ago
A "fun" exercise in C++ is to take a line of code that makes extensive use of advanced features, like templates, smart pointers, etc. and step through a -O0 compile with gdb. I was shocked, in some cases, about how many different functions were called for what looks like a simple expression.
This can lead to some interesting errors. For example, writing
void foo(const std::string s)
by mistake, instead of
void foo(const std::string &s)
won't result in a compiler error, but will result in an unusually large, and unexpected overhead in calling foo.
On the other hand, STL is great (less the error messages). I sorely miss it when programming in C.
- loup-vaillant 15y ago> I sorely miss [the STL] when programming in C. Well, C++ got at least one thing right: deciding to support parametric polymorphism (or "genericity"). Templates are quite ugly, but at least they do the job.