Pull to refresh
279.62

C++ *

General-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation

Show first
Rating limit
Level of difficulty

Diamond inheritance problem is not a problem, that's a tricky feature

Reading time7 min
Views4.4K

General


Before discussing the topic I’d like to start with a general suggestion not to use multiple inheritance and especially diamond unless you are strongly forced to. You may use e.g. composition or aggregation instead.


Well, “Diamond inheritance problem” is some kind of steady expression which formed many years ago. You can easily find a lot of articles suggesting usage of “virtual public” to avoid the ambiguity and so on. For instance, https://en.wikipedia.org/wiki/Multiple_inheritance


image


 That is not wrong as for the problem stated but anyway it is quite one-side statement.
 Below you can find:


  • difference in memory allocation and initialization order between public and public virtual inheritance (examples 1, 2),
  • examples of practical usage of both public and public virtual inheritance (examples 3, 4).
Read more →

A Second Check of Newton Game Dynamics with PVS-Studio

Reading time10 min
Views651

Рисунок 1

Some time ago, somewhere on the Internet, I stumbled upon a physics engine called Newton Game Dynamics. Knowing that engine projects are usually big and complex, I decided to check its code with PVS-Studio for any interesting defects. I was especially enthusiastic about this one because my co-worker Andrey Karpov already checked it in 2014 and a second check would be a good opportunity to demonstrate our analyzer's evolution over the past six years. As of this writing, the latest version of Newton Game Dynamics is dated February 27, 2020, which means it has been actively developing for the past six years too. So, hopefully, this article will be interesting not only to us but to the engine's developers as well – and for them it's a chance to fix some bugs and improve their code.
Read more →

Checking the GCC 10 Compiler with PVS-Studio

Reading time9 min
Views1.7K

PVS-Studo vs GCC 10

The GCC compiler is written with copious use of macros. Another check of the GCC code using PVS-Studio once again confirms the opinion of our team that macros are evil in the flesh. Not only does the static analyzer struggle with reviewing such code, but also a developer. GCC developers are certainly used to the project and are well versed in it. Nonetheless, it is very difficult to understand something on the third hand. Actually, due to macros, it was not possible to fully perform code checking. However, the PVS-Studio analyzer, as always, showed that it can find errors even in compilers.
Read more →

Starting My Collection of Bugs Found in Copy Functions

Reading time4 min
Views810

memcpy

I've already noticed a few times before that programmers seem to tend to make mistakes in simple copy functions. Writing a profound article on this topic is going to take quite a while since I'll have to do some thorough research and sample collecting, but for now I'd like to share a couple of examples I stumbled upon recently.
Read more →

How Deep the Rabbit Hole Goes, or C++ Job Interviews at PVS-Studio

Reading time4 min
Views1.8K

Job Interviews at PVS-Studio

Authors: Andrey Karpov, khandeliants Phillip Khandeliants.
Here's an interesting story about how one of the questions we ask at job interviews turned out to reach even deeper than intended by its author. You've always got to watch your step with C++ and C++ compilers – there's never a risk of getting bored.
Read more →

Checking the Code of Zephyr Operating System

Reading time13 min
Views2K

PVS-Studio and Zephyr

Some time ago we announced PVS-Studio's new feature that enabled it to integrate into PlatformIO. Naturally, our team kept in touch with the PlatformIO team while working on that feature, and they suggested that we check the real-time operating system Zephyr to see if we could find any interesting bugs in its code. We thought it was a good idea, and so here's this article about the check results.
Read more →

OpenToonz: inside and out

Reading time10 min
Views688
Picture 1

Almost four years have passed since the PVS-Studio team checked the OpenToonz source code. This project is a very powerful tool for creating two-dimensional animation. Since the last check, with its help, such animated works as Mary and the Witch Flower, Batman-Ninja, Promare and others were created. As large studios continue using Toonz, why not check the quality of the source code again?
Read more →

Analyze your builds programmatically with the C++ Build Insights SDK

Reading time4 min
Views2K
We’re happy to announce today the release of the C++ Build Insights SDK, a framework that gives you access to MSVC build time information via C and C++ APIs. To accompany this release, we are making vcperf open source on GitHub. Because vcperf itself is built with the SDK, you can use it as a reference when developing your own tools. We’re excited to see what sort of applications you’ll be building with the SDK, and we’re looking forward to receiving your feedback!

Read more →

Zero, one, two, Freddy's coming for you

Reading time23 min
Views1.4K

Рисунок 1

This post continues the series of articles, which can well be called «horrors for developers». This time it will also touch upon a typical pattern of typos related to the usage of numbers 0, 1, 2. The language you're writing in doesn't really matter: it can be C, C++, C#, or Java. If you're using constants 0, 1, 2 or variables' names contain these numbers, most likely, Freddie will come to visit you at night. Go on, read and don't say we didn't warn you.
Read more →

What’s New in Visual Studio 2019 version 16.5 Preview 2 for C++, Xamarin, and Azure Tooling Experiences

Reading time3 min
Views1.4K
Last week, Visual Studio 2019 version 16.5 Preview 2 was released, bringing many new features and improvements for developers in Visual Studio to help you build better software faster. Please read some highlights of new features and improved developer experiences in this page.



Install this preview side-by-side with your Visual Studio release and try these highlighted features without replacing your current development environment.

Read more →

VVVVVV??? VVVVVV!!! :)

Reading time10 min
Views2.3K
If you're reading this text, you've either thought that something was wrong with the headline or you've seen the name of a familiar computer game. VVVVVV is an indie platformer game that has stolen the hearts of many players by its pleasant external simplicity and no less pleasant internal complexity. A few days ago, VVVVVV turned 10 years, and the author of the game — Terry Cavanagh — celebrated this holiday by publishing its source code. What mind-boggling things is it hiding? Read the answer in this article.

Рисунок 1
Read more →

C++ Inliner Improvements: The Zipliner

Reading time3 min
Views850
Visual Studio 2019 versions 16.3 and 16.4 include improvements to the C++ inliner. Among these is the ability to inline some routines after they have been optimized, referred to as the «Zipliner.» Depending on your application, you may see some minor code quality improvements and/or major build-time (compiler throughput) improvements. 

Read more →

What Is MISRA and how to Cook It

Reading time11 min
Views1.1K

Рисунок 2

Perhaps every microcontroller software developer has heard about special coding standards to help improve the code security and portability. One of such standards is MISRA. In this article, we'll take a closer look at what this standard is, its concept and how to use it in your projects.
Read more →

Top 10 Bugs Found in C++ Projects in 2019

Reading time8 min
Views2K

Picture 7

Another year is drawing to an end, and it's a perfect time to make yourself a cup of coffee and reread the reviews of bugs collected across open-source projects over this year. This would take quite a while, of course, so we prepared this article to make it easier for you. Today we'll be recalling the most interesting dark spots that we came across in open-source C/C++ projects in 2019.
Read more →

Quick reference of C++ value categories: Part 2

Reading time41 min
Views2.7K



Go to Part 1


Passing parameters to a function


When passing parameter to a function, category of a passed expression is implicitly converted to the category of function parameter: void f(TO_TYPE p); FROM_TYPE x; f(x); This implicit conversion takes place the same way as during an assignment (see "Assignment" section above) except that function definition cannot contain "auto" types.


Read more →

Quick reference of C++ value categories: Part 1

Reading time13 min
Views7.6K

image

The goal of this quick reference is to collect in one place and organize information about value categories in C++, assignment, parameter passing and returning from functions. I tried to make this quick reference convenient to quickly compare and select one of solutions possible, this is why I made several tables here.


For introduction to the topic, please use the following links:


C++ rvalue references and move semantics for beginners
Rvalues redefined
C++ moves for people who don’t know or care what rvalues are
Scott Meyers. Effective Modern C++. 2015
Understanding Move Semantics and Perfect Forwarding: Part 1
Understanding Move Semantics and Perfect Forwarding: Part 2
Understanding Move Semantics and Perfect Forwarding: Part 3
Do we need move and copy assignment

Read more →