basics

Cppcheck

I wish to introduce the CppCheck tool to the beginner programmers. Cppcheck is a static analyzer for C and C++ code. It is open-source, free, cross-platform and easy-to-use.

Cppcheck

by Andrey Karpov

From the article:

One of the basic advantages of the Cppcheck analyzer is that it is easy-to-use. It is good to teach and study the static analysis methodology: for instance, you install Cppcheck on a Windows system and get a GUI interface allowing you to immediately start checking your projects.

The Rule of Zero revisited: The Rule of All or Nothing--Arne Mertz

In this article you will find a new rule of thumb:

The Rule of Zero revisited: The Rule of All or Nothing

by Arne Mertz

From the article:

In 2012, Martinho Fernandes coined the Rule of Zero in a blog post. In 2014, Scott Meyers wrote a blog post about a concern with that rule and proposed a Rule of Five Defaults.

Back then, I had written a small comment on Scott’s post that deserves some further elaboration. In this post I am going to wrap up my thoughts about the two posts and propose a “Rule of All or Nothing”...

Still Comparing "this" Pointer to Null?--Dmitry Meshcheryakov

The article explains why one must never use the (this == 0) expression. It's a very bad code. It being able to work at times doesn't mean anything. By writing (this == 0), you let undefined behavior into your program.

Still Comparing "this" Pointer to Null?

by Dmitry Meshcheryakov

From the article:

In the same way the compiler can optimize the code comparing "this" pointer to null. According to the Standard, this cannot be null and therefore the checks and the corresponding code branches can be eliminated, which will greatly affect the code dependent on the comparison of "this" pointer to null. The compiler has a full right to "break" (actually just break it further) the code CWindow::GetSafeHandle() and generate machine code which doesn't contain the comparison and only reads the class field all the time.
...
GOOD LORD, the "this" pointer equals 0x00000004 on entering the method when compiled in Visual C++ 9, as the pointer initially set to null is adjusted so that it points to the beginning of a subobject of the corresponding class.

No need to square, sum, and sqrt manually anymore--Indi

A useful remainder for programmers, the std::hypot function:

No need to square, sum, and sqrt manually anymore

by Indi

From the article:

I hang out a lot with engineers and game programmers, so that means I tend to see a lot of code dealing with physics problems. One of the most commonly used bits of code in both domains has to be the Euclidean distance equation. However, few programmers realize that that equation is a lot easier than it used to be...

C++ User Group Meetings in February

New month, and a few more C++ User Group Meetings:

C++ User Group Meetings in February

by Jens Weller

From the article:

Again an overview on the upcoming meetings of C++ User Groups. This time, its February again, the shortest, and in a lot of places coldest month of the year. Still, 19 C++ User Groups have already...

The Meetings:

4.2 C++ UG Saint Louis - DD Part 2 - Lambdas
7.2 C++ UG Italy - Pordenone
11.2 C++ UG Utah - Asynchronous Messaging with ØMQ
11.2 C++ UG San Francisco/ Bay area - CopperSpice
11.2 C++ UG Santa Barbara - Introduction to OpenGL with SDL
12.2 C++ UG Dresden - Clean code in asynchronous Programming
12.2 C++ UG Wroclaw - Databases & C++: SOCI, boost::python
16.2 C++ UG Denver - Denver Tech Center C++ Developers
16.2 C++ UG Austin - North Austin Monthly C/C++ Pub Social
17.2 C++ UG Berlin - First meeting at think-cell
18.2 C++ UG Bristol - Kevlin Henney: Making Steaks from Sacred Cows
18.2 C++ UG Düsseldorf - Treffen der C++ User Gruppe NRW
18.2 C++ UG Hamburg - Treffen der C++ User Gruppe Hamburg
19.2 C++ UG Ruhrgebiet - February C++ Meetup in the Ruhr area
21.2 C++ UG Pune, India - Introduction to Concurrency and Memory Models
24.2 C++ UG Warsaw - Overload resolution oraz Zakamarki C++
24.2 C++ UG Edinburgh - First Meeting
25.2 C++ UG San Francisco/ Bay area - Workshop and Discussion Group
26.2 C++ UG Munich - "Dreaming of Names" and "A short (and practical) introduction to

Know your libraries -- Arne Mertz

Prefer standard library over handcrafted logic/algorithm.

Know your libraries

by Arne Mertz

From the article:

I often see people use handcrafted loops or write weird workarounds for stuff the standard library has already taken care of. This does not only apply for standard library features but also for any other library, like Boost, other third party libraries and the libraries the code belongs to. That is bad for several reasons, and I am going to lay out what I think every developer should be required to do before he writes production code.

Two fundamental implementations for one conceptual object -- Mark Isaacson

From the Modern Maintainable Code blog:

Two fundamental implementations for one conceptual object

by Mark Isaacson

From the article:

This is the third article of a series on code reuse. This article discusses how to select between implementations of an object based on patterns in type information. The article uses std::unique_ptr's deleter as a practical case study.

You can find the previous article of the series here (which discusses the analogous problem as it pertains to functions), and the prelude to the next article, which looks at the same problem with one caveat: designing it so that some, but not all, of the methods will be implemented the same way no matter what types you instantiate the object with, here.

Yes, we must replace it++ with ++it--Andrey Karpov

I decided to find out if there is practical sense in writing ++iterator instead of iterator++ when handling iterators.

Is it reasonable to use the prefix increment operator ++it instead of postfix operator it++ for iterators?

by Andrey Karpov

From the article:

I will always write ++it. I did so before but I did it "just in case". Now I can see how useful it is because I regularly launch debug versions. In general, of course, ++it has a very slight influence on the running time. But if I don't make such small optimizations in different places of the code, it will be too late and the profiler won't help me. Bottlenecks will be spread throughout the code.