SlideShare a Scribd company logo
1 of 37
Effective C++
Andrey Karpov
Microsoft MVP,
Ph. D. in Physical and Mathematical Sciences, CTO
karpov@viva64.com
•IBM RPG is a programming
language with a syntax that was
originally similar to the command
language of IBM mechanical
tabulating machines
•It was widely used in 1960s and
1970s
IBM 1401
Are C and C++ alive? Even IBM RPG is still
alive!
break in switch: problem
....
case ADDRESS_HOME_LINE3:
group = GROUP_ADDRESS_LINE_3;
break;
case ADDRESS_HOME_STREET_ADDRESS:
group = GROUP_STREET_ADDRESS;
case ADDRESS_HOME_CITY:
group = GROUP_ADDRESS_CITY;
break;
case ADDRESS_HOME_STATE:
group = GROUP_ADDRESS_STATE;
break;
....
Chromium
break in switch: huge problem
• Qt
• GDB
• Redis
• EA WebKit
• Unreal Engine 4
• Chromium
• ....
break in switch: interim solutions
• MISRA: a non-empty case should always be completed by
the operator break
• [[gnu::fallthrough]]
• [[clang::fallthrough]]
• __attribute__((fallthrough))
• BOOST_FALLTHROUGH
break в switch: [[fallthrough]]
switch (i)
{
case 10:
f1();
break;
case 20:
f2();
break;
case 30:
f3();
[[fallthrough]]; // The warning will be suppressed
case 40:
f4();
break;
Clang, GCC: -Wimplicit-fallthrough
C++17: features that were removed
• Trigraphs were removed
• The register keyword cannot be used as a variable
specifier
• Prefix and postfix increments for bool type were
removed
• V552 diagnostic in PVS-Studio analyzer will become irrelevant
• std::auto_ptr was removed, std::unique_ptr should
be used instead
??= #
??/ 
??' ^
??( [
??) ]
??! |
??< {
??> }
??- ~
Non-constant string::data
• In C++17, std::string now has the data() method, which
returns a non-constant pointer to the internal data of a
string.
• Now I believe that we are really being taken care of. A
PRACTICAL problem is actually solved.
It wasn’t nice to write &str.front() and &str[0]
std::string str = "hello";
char *p = str.data();
p[0] = 'H';
std::cout << str << 'n'; // Hello
New attribute [[nodiscard]]
[[nodiscard]] int Sum(int a, int b)
{
return a + b;
}
int main()
{
Sum(5, 6); // Compiler/analyzer
// warning will be issued
return 0;
}
A custom string class is normal
• Sooner or later, any decent project
obtains its own string class.
• I've been waiting for it to appear in PVS-
Studio.
• It appeared in our project and it was a
justified decision.
• It is normal. Feel free to do it.
From my report for C++ Russia 2016
std::string
• C++ Russia 2017: Anton Polukhin «What not to do: C++
wheel reinventing for professionals» (RU)
https://youtu.be/rJWSSWYL83U
• vstring
• std::string
Constexpr if
template <typename T>
auto GetValue(T t)
{
if constexpr (std::is_pointer<T>::value)
{
return *t;
}
else
{
return t;
}
}
void foo()
{
int v = 10;
std::cout << GetValue(v) << 'n'; // 10
std::cout << GetValue(&v) << 'n'; // 10
}
Initializer in if and switch
if ((len=input.find("length=",start)!=std::string::npos))
length=atoi(&(input.c_str()[len+strlen("length=")]));
SETI@home
Initializer in if and switch
if (auto it = m.find(key); it != m.end())
{
....
}
__has_include
#if __has_include(<optional>)
#include <optional>
#define have_optional 1
#elif __has_include(<experimental/optional>)
#include <experimental/optional>
#define have_optional 1
#define experimental_optional 1
#else
#define have_optional 0
#endif
С++17: one last thing
• I recommend the article of my colleague Egor Bredikhin:
"C++17"
https://www.viva64.com/en/b/0533/
The maturity of tools
• Compilers
• Development environments
• Dynamic analyzers
• Static analyzers
Dynamic analyzers
• Classic:
• Valgrind
• BoundsChecker
• Intel Parallel Inspector
• Novelties from Google:
• AddressSanitizer
• ThreadSanitizer
• MemorySanitizer
Static code analyzers
• Coverity
• Klocwork
• Parasoft
• PVS-Studio
• SonarQube
• "Legion is their name": List of tools for static code analysis
https://en.wikipedia.org/wiki/List_of_tools_for_static_code_
analysis
Modern C++ doesn’t eliminate the need for
static analysis
TDLib (C++)void FileGcWorker::run_gc(....,
std::vector<FullFileInfo> files, ....)
{
....
std::sort(files.begin(), files.end(),
[](const auto &a, const auto &b)
{
return a.atime_nsec < a.atime_nsec;
});
....
}
Static analysis isn’t a patch for C and C++
static bool AreEqual( VisualStyleElement value1,
VisualStyleElement value2)
{
return
value1.ClassName == value1.ClassName &&
value1.Part == value2.Part &&
value1.State == value2.State;
}
Mono (C#)
PVS-Studio
• I would like to introduce Mikhail Matrosov
• Technical manager in the Moscow R&D Office of the Align Technology
company
General information
• Align Technology R&D
• 1.5M LOC C++
• Including a very dusty legacy :)
• 150 commits per day
• 5 developers per month :)
Automation
• CI Server (Bamboo)
• Daily build for the incremental analysis (approx. 15 minutes)
• Night build for full analysis (approx. 6 hours)
• L3 are not checked
Process from a developer's perspective
• Upload the changes to trunk
• On the CI server, a build with incremental analysis is automatically
started
• If the analysis finds PVS-Studio violations, I get a notice
• Correct the violations. I can check locally. Upload.
Process from the implementer’s point of view
• Every morning I check the results of a full analysis
• If there are violations, it means that either
• someone of developers missed a notification, in this case, I write a reminding
letter to him, or
• something went wrong in the process of the analysis, or notification wasn’t
sent, in this case, I investigate the issue
• If a developer often misses notifications, I have an educational
conversation with him
Deployment
• Full analysis of the sources
• Reviewing each rule - to which extent it applies to our codebase
• If a rule gives too many false positives, it is removed from the analysis using
the .pvsconfig file
• A small number of the most terrible violations must be fixed
immediately
• Suppress all other violations
Overall impression
• The tool is quite simple in deployment and configuration
• Helped to find many real problems. The process is established and
works well enough.
• The authors quickly respond and quickly fix the problems. Can
implement a feature on request.
• The analyzer is often mistaken on complex C++ code. Lack of reliable
parser (clang) has its impact. There is a feeling that this will not
improve. At the moment it seems that duck tape is used when
needed.
Acceleration of build: distributed
compilation
• IncrediBuild - https://www.incredibuild.com/
• distcc - https://github.com/distcc/distcc
• Icecream - https://github.com/icecc/icecream
Acceleration of build: compiler cache
• When compiling a preprocessed file on the basis of its
contents, compiler flags and the output from the compiler,
the hash value is calculated
• If you recompile an unchanged file with the same flags, a
ready-made object file will be taken out from the cache and
fed to the linker input
Acceleration of build: compiler cache
Acceleration of build: compiler cache
•For Unix-like systems:
• ccache (GCC, Clang) - https://ccache.samba.org/
• cachecc1 (GCC) - http://cachecc1.sourceforge.net/
•For Windows:
• clcache (MSVC) - https://github.com/frerich/clcache
• cclash (MSVC) - https://github.com/inorton/cclash
Acceleration of build: replacement of
translation components
• Multiplied acceleration of project recompilation
• Zapcc vs Clang
Acceleration of build: modules
• Waiting for C++20
Profiling tools of C++ code
• As the saying goes, let me "pass by reference" your attention to this
report.
• Alexander Zaitsev. Profiling tools of C++ code.
Minsk, CoreHard C++ Conference in Spring 2018
• The video will become available on YouTube in 3 months
and so on
• C++ Core Guidelines
• Community, conferences
• The job market
Answering your questions
Andrey Karpov karpov@viva64.com
PVS-Studio web site https://www.viva64.com
Twitter @Code_Analysis

More Related Content

What's hot

'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro GusevOdessaJS Conf
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Lars Thorup
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Practical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint ProgrammingPractical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint Programminged271828
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutinesRoman Elizarov
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective SystemMarcus Denker
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India
 
Building Open-Source React Components
Building Open-Source React ComponentsBuilding Open-Source React Components
Building Open-Source React ComponentsZack Argyle
 
Building Open-source React Components
Building Open-source React ComponentsBuilding Open-source React Components
Building Open-source React ComponentsZack Argyle
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscriptBill Buchan
 
Mock cli with Python unittest
Mock cli with Python unittestMock cli with Python unittest
Mock cli with Python unittestSong Jin
 
SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3Ben Lesh
 
What I Learned From Writing a Test Framework (And Why I May Never Write One A...
What I Learned From Writing a Test Framework (And Why I May Never Write One A...What I Learned From Writing a Test Framework (And Why I May Never Write One A...
What I Learned From Writing a Test Framework (And Why I May Never Write One A...Daryl Walleck
 
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...Nikita Lipsky
 
Infrastructure as code might be literally impossible
Infrastructure as code might be literally impossibleInfrastructure as code might be literally impossible
Infrastructure as code might be literally impossibleice799
 

What's hot (20)

'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
 
Test driving-qml
Test driving-qmlTest driving-qml
Test driving-qml
 
Iron Sprog Tech Talk
Iron Sprog Tech TalkIron Sprog Tech Talk
Iron Sprog Tech Talk
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Practical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint ProgrammingPractical RISC-V Random Test Generation using Constraint Programming
Practical RISC-V Random Test Generation using Constraint Programming
 
Introduction to Kotlin coroutines
Introduction to Kotlin coroutinesIntroduction to Kotlin coroutines
Introduction to Kotlin coroutines
 
Pharo: A Reflective System
Pharo: A Reflective SystemPharo: A Reflective System
Pharo: A Reflective System
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JIT
 
Building Open-Source React Components
Building Open-Source React ComponentsBuilding Open-Source React Components
Building Open-Source React Components
 
Building Open-source React Components
Building Open-source React ComponentsBuilding Open-source React Components
Building Open-source React Components
 
Programming
ProgrammingProgramming
Programming
 
Speed geeking-lotusscript
Speed geeking-lotusscriptSpeed geeking-lotusscript
Speed geeking-lotusscript
 
Mock cli with Python unittest
Mock cli with Python unittestMock cli with Python unittest
Mock cli with Python unittest
 
Perl-Critic
Perl-CriticPerl-Critic
Perl-Critic
 
Is Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic GascIs Python still production ready ? Ludovic Gasc
Is Python still production ready ? Ludovic Gasc
 
SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3SF Front End Developers - Ember + D3
SF Front End Developers - Ember + D3
 
What I Learned From Writing a Test Framework (And Why I May Never Write One A...
What I Learned From Writing a Test Framework (And Why I May Never Write One A...What I Learned From Writing a Test Framework (And Why I May Never Write One A...
What I Learned From Writing a Test Framework (And Why I May Never Write One A...
 
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
 
Infrastructure as code might be literally impossible
Infrastructure as code might be literally impossibleInfrastructure as code might be literally impossible
Infrastructure as code might be literally impossible
 

Similar to Effective C++

Static-Analysis-in-Industry.pptx
Static-Analysis-in-Industry.pptxStatic-Analysis-in-Industry.pptx
Static-Analysis-in-Industry.pptxShivashankarHR1
 
PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)Andrey Karpov
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroMohammad Shaker
 
9781285852744 ppt ch01
9781285852744 ppt ch019781285852744 ppt ch01
9781285852744 ppt ch01Terry Yoast
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017Andrey Karpov
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLintLeander Hasty
 
How to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator ProjectHow to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator ProjectSimon Urli
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin敬倫 林
 
PAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLERPAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLERNeotys
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentAdaCore
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceESUG
 
Achieving Full Stack DevOps at Colonial Life
Achieving Full Stack DevOps at Colonial Life Achieving Full Stack DevOps at Colonial Life
Achieving Full Stack DevOps at Colonial Life DevOps.com
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Fwdays
 
OptView2 MUC meetup slides
OptView2 MUC meetup slidesOptView2 MUC meetup slides
OptView2 MUC meetup slidesOfek Shilon
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++Vaibhav Khanna
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016maiktoepfer
 

Similar to Effective C++ (20)

Static-Analysis-in-Industry.pptx
Static-Analysis-in-Industry.pptxStatic-Analysis-in-Industry.pptx
Static-Analysis-in-Industry.pptx
 
PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 
9781285852744 ppt ch01
9781285852744 ppt ch019781285852744 ppt ch01
9781285852744 ppt ch01
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLint
 
How to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator ProjectHow to Design a Program Repair Bot? Insights from the Repairnator Project
How to Design a Program Repair Bot? Insights from the Repairnator Project
 
Week1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC BeginWeek1 Electronic System-level ESL Design and SystemC Begin
Week1 Electronic System-level ESL Design and SystemC Begin
 
PAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLERPAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLER
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise Environment
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Rakuten openstack
Rakuten openstackRakuten openstack
Rakuten openstack
 
Achieving Full Stack DevOps at Colonial Life
Achieving Full Stack DevOps at Colonial Life Achieving Full Stack DevOps at Colonial Life
Achieving Full Stack DevOps at Colonial Life
 
Return of c++
Return of c++Return of c++
Return of c++
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
OptView2 MUC meetup slides
OptView2 MUC meetup slidesOptView2 MUC meetup slides
OptView2 MUC meetup slides
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 
Effective code reviews
Effective code reviewsEffective code reviews
Effective code reviews
 

More from Andrey Karpov

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программистаAndrey Karpov
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developerAndrey Karpov
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Andrey Karpov
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesAndrey Karpov
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewAndrey Karpov
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокAndrey Karpov
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Andrey Karpov
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesAndrey Karpov
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?Andrey Karpov
 
Typical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaAndrey Karpov
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)Andrey Karpov
 
Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Andrey Karpov
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareAndrey Karpov
 
Static Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineAndrey Karpov
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsAndrey Karpov
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++Andrey Karpov
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youAndrey Karpov
 

More from Andrey Karpov (20)

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developer
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature Overview
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок
 
PVS-Studio в 2021
PVS-Studio в 2021PVS-Studio в 2021
PVS-Studio в 2021
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
 
Typical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and Java
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
 
Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
 
Static Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal Engine
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
 

Recently uploaded

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Recently uploaded (20)

Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 

Effective C++

  • 1. Effective C++ Andrey Karpov Microsoft MVP, Ph. D. in Physical and Mathematical Sciences, CTO karpov@viva64.com
  • 2. •IBM RPG is a programming language with a syntax that was originally similar to the command language of IBM mechanical tabulating machines •It was widely used in 1960s and 1970s IBM 1401 Are C and C++ alive? Even IBM RPG is still alive!
  • 3. break in switch: problem .... case ADDRESS_HOME_LINE3: group = GROUP_ADDRESS_LINE_3; break; case ADDRESS_HOME_STREET_ADDRESS: group = GROUP_STREET_ADDRESS; case ADDRESS_HOME_CITY: group = GROUP_ADDRESS_CITY; break; case ADDRESS_HOME_STATE: group = GROUP_ADDRESS_STATE; break; .... Chromium
  • 4. break in switch: huge problem • Qt • GDB • Redis • EA WebKit • Unreal Engine 4 • Chromium • ....
  • 5. break in switch: interim solutions • MISRA: a non-empty case should always be completed by the operator break • [[gnu::fallthrough]] • [[clang::fallthrough]] • __attribute__((fallthrough)) • BOOST_FALLTHROUGH
  • 6. break в switch: [[fallthrough]] switch (i) { case 10: f1(); break; case 20: f2(); break; case 30: f3(); [[fallthrough]]; // The warning will be suppressed case 40: f4(); break; Clang, GCC: -Wimplicit-fallthrough
  • 7. C++17: features that were removed • Trigraphs were removed • The register keyword cannot be used as a variable specifier • Prefix and postfix increments for bool type were removed • V552 diagnostic in PVS-Studio analyzer will become irrelevant • std::auto_ptr was removed, std::unique_ptr should be used instead ??= # ??/ ??' ^ ??( [ ??) ] ??! | ??< { ??> } ??- ~
  • 8. Non-constant string::data • In C++17, std::string now has the data() method, which returns a non-constant pointer to the internal data of a string. • Now I believe that we are really being taken care of. A PRACTICAL problem is actually solved. It wasn’t nice to write &str.front() and &str[0] std::string str = "hello"; char *p = str.data(); p[0] = 'H'; std::cout << str << 'n'; // Hello
  • 9. New attribute [[nodiscard]] [[nodiscard]] int Sum(int a, int b) { return a + b; } int main() { Sum(5, 6); // Compiler/analyzer // warning will be issued return 0; }
  • 10. A custom string class is normal • Sooner or later, any decent project obtains its own string class. • I've been waiting for it to appear in PVS- Studio. • It appeared in our project and it was a justified decision. • It is normal. Feel free to do it. From my report for C++ Russia 2016
  • 11. std::string • C++ Russia 2017: Anton Polukhin «What not to do: C++ wheel reinventing for professionals» (RU) https://youtu.be/rJWSSWYL83U • vstring • std::string
  • 12. Constexpr if template <typename T> auto GetValue(T t) { if constexpr (std::is_pointer<T>::value) { return *t; } else { return t; } } void foo() { int v = 10; std::cout << GetValue(v) << 'n'; // 10 std::cout << GetValue(&v) << 'n'; // 10 }
  • 13. Initializer in if and switch if ((len=input.find("length=",start)!=std::string::npos)) length=atoi(&(input.c_str()[len+strlen("length=")])); SETI@home
  • 14. Initializer in if and switch if (auto it = m.find(key); it != m.end()) { .... }
  • 15. __has_include #if __has_include(<optional>) #include <optional> #define have_optional 1 #elif __has_include(<experimental/optional>) #include <experimental/optional> #define have_optional 1 #define experimental_optional 1 #else #define have_optional 0 #endif
  • 16. С++17: one last thing • I recommend the article of my colleague Egor Bredikhin: "C++17" https://www.viva64.com/en/b/0533/
  • 17. The maturity of tools • Compilers • Development environments • Dynamic analyzers • Static analyzers
  • 18. Dynamic analyzers • Classic: • Valgrind • BoundsChecker • Intel Parallel Inspector • Novelties from Google: • AddressSanitizer • ThreadSanitizer • MemorySanitizer
  • 19. Static code analyzers • Coverity • Klocwork • Parasoft • PVS-Studio • SonarQube • "Legion is their name": List of tools for static code analysis https://en.wikipedia.org/wiki/List_of_tools_for_static_code_ analysis
  • 20. Modern C++ doesn’t eliminate the need for static analysis TDLib (C++)void FileGcWorker::run_gc(...., std::vector<FullFileInfo> files, ....) { .... std::sort(files.begin(), files.end(), [](const auto &a, const auto &b) { return a.atime_nsec < a.atime_nsec; }); .... }
  • 21. Static analysis isn’t a patch for C and C++ static bool AreEqual( VisualStyleElement value1, VisualStyleElement value2) { return value1.ClassName == value1.ClassName && value1.Part == value2.Part && value1.State == value2.State; } Mono (C#)
  • 22. PVS-Studio • I would like to introduce Mikhail Matrosov • Technical manager in the Moscow R&D Office of the Align Technology company
  • 23. General information • Align Technology R&D • 1.5M LOC C++ • Including a very dusty legacy :) • 150 commits per day • 5 developers per month :)
  • 24. Automation • CI Server (Bamboo) • Daily build for the incremental analysis (approx. 15 minutes) • Night build for full analysis (approx. 6 hours) • L3 are not checked
  • 25. Process from a developer's perspective • Upload the changes to trunk • On the CI server, a build with incremental analysis is automatically started • If the analysis finds PVS-Studio violations, I get a notice • Correct the violations. I can check locally. Upload.
  • 26. Process from the implementer’s point of view • Every morning I check the results of a full analysis • If there are violations, it means that either • someone of developers missed a notification, in this case, I write a reminding letter to him, or • something went wrong in the process of the analysis, or notification wasn’t sent, in this case, I investigate the issue • If a developer often misses notifications, I have an educational conversation with him
  • 27. Deployment • Full analysis of the sources • Reviewing each rule - to which extent it applies to our codebase • If a rule gives too many false positives, it is removed from the analysis using the .pvsconfig file • A small number of the most terrible violations must be fixed immediately • Suppress all other violations
  • 28. Overall impression • The tool is quite simple in deployment and configuration • Helped to find many real problems. The process is established and works well enough. • The authors quickly respond and quickly fix the problems. Can implement a feature on request. • The analyzer is often mistaken on complex C++ code. Lack of reliable parser (clang) has its impact. There is a feeling that this will not improve. At the moment it seems that duck tape is used when needed.
  • 29. Acceleration of build: distributed compilation • IncrediBuild - https://www.incredibuild.com/ • distcc - https://github.com/distcc/distcc • Icecream - https://github.com/icecc/icecream
  • 30. Acceleration of build: compiler cache • When compiling a preprocessed file on the basis of its contents, compiler flags and the output from the compiler, the hash value is calculated • If you recompile an unchanged file with the same flags, a ready-made object file will be taken out from the cache and fed to the linker input
  • 31. Acceleration of build: compiler cache
  • 32. Acceleration of build: compiler cache •For Unix-like systems: • ccache (GCC, Clang) - https://ccache.samba.org/ • cachecc1 (GCC) - http://cachecc1.sourceforge.net/ •For Windows: • clcache (MSVC) - https://github.com/frerich/clcache • cclash (MSVC) - https://github.com/inorton/cclash
  • 33. Acceleration of build: replacement of translation components • Multiplied acceleration of project recompilation • Zapcc vs Clang
  • 34. Acceleration of build: modules • Waiting for C++20
  • 35. Profiling tools of C++ code • As the saying goes, let me "pass by reference" your attention to this report. • Alexander Zaitsev. Profiling tools of C++ code. Minsk, CoreHard C++ Conference in Spring 2018 • The video will become available on YouTube in 3 months
  • 36. and so on • C++ Core Guidelines • Community, conferences • The job market
  • 37. Answering your questions Andrey Karpov karpov@viva64.com PVS-Studio web site https://www.viva64.com Twitter @Code_Analysis