SlideShare une entreprise Scribd logo
1  sur  41
The Great and Mighty C++
Andrey Karpov
karpov@viva64.com
www.reddit.com/r/programming
• SVG Is Turing Complete
• A step-by-step guide to analyzing JSON (and other semi-structured datasets) with SQL
• “Performance Matters” by Emery Berger (Strange Loop 2019)
• Why are large companies so difficult to rescue (regarding bad internal technology)
• Practical Ways to Write Better Javascript
• From UNIX to Linux, a time lapse of 45 years, Hendrik Jan Thomassen
• Stack Overflow Trends – Scala's decline mirrors Kotlin's rise
• Maximize learnings from a Kubernetes cluster failure
• Why Go and not Rust?
• Q&A: How Google Implements Code Coverage at Massive Scale
• Hierarchical Instrumented Tracing with Logback
• Court of appeals rules web scraping doesn't violate anti-hacking law - JavaScript Web Scraping
Guy
• Building GraphQL apis with Django
Everyone Just Lives in Their Own Reality
• С++ Russia x3 (Novosibirsk, Moscow, Saint Petersburg)
• CoreHard (Minsk)
• Meeting C++ (Berlin)
• CppCon (Colorado)
• C++Now (Colorado)
• Italian C++ Conference (Milan)
• emBO++ (Bochum)
• ....
Presenter:
• Andrey Karpov, PhD in physics and math
• Technical Director at SiProVer LLC
• Microsoft MVP
• Intel Black Belt Software Developer
• One of the PVS-Studio project’s founders
A Few Words About Us
• We stand on guard of code
quality.
• PVS-Studio detects errors and
potential vulnerabilities in С, C++,
C# and Java code.
• We actively participate in
conferences, do conference talks,
and write many articles dedicated
to code quality.
Are С and C++ alive? PDP Software Is!
•The PDP-11 mini-computer
Are С and C++ Alive? Even More, IBM RPG Is!
•IBM RPG is a programming
language whose syntax was
initially similar to the command
language of IBM’s mechanical
tabulators.
•Was widely used in 1960s and
1970s.
IBM 1401
C and C++ Are Not Just for Old Systems
• C++ Applications - http://www.stroustrup.com/applications.html
• Adobe Photoshop
• Mozilla Firefox
• Thunderbird
• World of Warcraft
• Apple – OS X
• Chrome (Launch date: September 2, 2008)
Are С and C++ Alive?
• TIOBE Index: if you add up C and C++, C/C++ will be the leader.
Summary for C, C++
• It’s a good idea to learn these languages
• There are and there will be many jobs for C/C++ developers
• The number of embedded systems in C is growing
Topics:
• Embedded systems
• A few words about innovations
• Development tool maturity and speeding up project builds
• The safe programming trend
• Various assistance tools that help control code quality
Embedded: C and С++ Are on the Rise
• Embedded
• IoT (Internet of Things)
Anticipated IoT Growth Rate
15.41
17.68
20.35
23.14
26.66
30.73
35.82
42.62
51.11
62.12
75.44
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025
Источник: https://www.statista.com/statistics/471264/iot-number-of-connected-devices-worldwide/
std::string
• C++ Russia 2017: Anton Polukhin, What Not to Do: C++, How
to Invent the Wheel Correctly (for Experts)
https://youtu.be/rJWSSWYL83U (in Russian)
• vstring
• std::string
C++17: 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
}
C++17: init-statement in if and switch
if (auto it = m.find(key); it != m.end())
{
....
}
C++17: A New Attribute [[fallthrough]]
switch (i)
{
case 10:
f1();
break;
case 20:
f2();
break;
case 30:
f3();
[[fallthrough]]; // The warning will be suppressed
case 40:
f4();
break;
}
C++17: A New Attribute [[nodiscard]]
[[nodiscard]] int Sum(int a, int b)
{
return a + b;
}
int main()
{
Sum(5, 6); // A compiler/analyzer
// will issue a warning
return 0;
}
C++17: Fold Expressions
template<typename... Args>
auto Sum(Args... args)
{
return (args + ...);
}
int main()
{
std::cout << Sum(1, 2, 3, 4, 5) << 'n'; // 15
return 0;
}
С++17: Removed Features
• Trigraphs were removed.
• The register keyword cannot be used as a variable specifier
anymore.
• Prefix and postfix increment operators for type bool
removed.
• std::auto_ptr was removed. Use std::unique_ptr instead.
С++17: And So On
• I recommend an article by my colleague, Egor Bredikhin
"C++17"
https://www.viva64.com/en/b/0533/
Speed up Your Project Build: Distributed
Compilation
• IncrediBuild - https://www.incredibuild.com/
• distcc - https://github.com/distcc/distcc
• Icecream - https://github.com/icecc/icecream
Speed up Your Project Build: Compiler Cache
• When you compile a preprocessed file, a hash value is
calculated based on the file’s contents, the compilation flags,
and the compiler’s output.
• When you recompile an unchanged file that has the same
flags, the compiler retrieves a ready-made file from cache
and feeds it to the linker.
Speed up Your Project Build: Compiler Cache
Speed up Your Project 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
Speed up Your Project Build: More Information
• See my colleague Phillip Khandeliants’s article
"Speeding up the Build of C and C++ Projects"
https://www.viva64.com/en/b/0549/
A Tool’s Maturity Level
• Compilers
• Development environments
• Dynamic analyzers
• Static analyzers
Dynamic Analyzers
• Classic tools:
• Valgrind
• BoundsChecker
• Intel Parallel Inspector
• New from Google:
• AddressSanitizer
• ThreadSanitizer
• MemorySanitizer
Static Code Analyzers
• Coverity
• Klocwork
• Parasoft
• PVS-Studio
• SonarQube
• “Their name is Legion": List of tools for static code analysis
https://en.wikipedia.org/wiki/List_of_tools_for_static_code_
analysis
PVS-Studio
• C, C++, C#, Java
• Windows, Linux и macOS
• https://www.viva64.com/
• Ways to Get a Free License
https://www.viva64.com/en/b/0614/
static const int kDaysInMonth[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
bool ValidateDateTime(const DateTime& time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
time.day < 1 || time.day > 31 ||
time.hour < 0 || time.hour > 23 ||
time.minute < 0 || time.minute > 59 ||
time.second < 0 || time.second > 59) {
return false;
}
if (time.month == 2 && IsLeapYear(time.year)) {
return time.month <= kDaysInMonth[time.month] + 1;
} else {
return time.month <= kDaysInMonth[time.month];
}
} 33
static const int kDaysInMonth[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
bool ValidateDateTime(const DateTime& time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
time.day < 1 || time.day > 31 ||
time.hour < 0 || time.hour > 23 ||
time.minute < 0 || time.minute > 59 ||
time.second < 0 || time.second > 59) {
return false;
}
if (time.month == 2 && IsLeapYear(time.year)) {
return time.month <= kDaysInMonth[time.month] + 1;
} else {
return time.month <= kDaysInMonth[time.month];
}
} 34
static const int kDaysInMonth[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
bool ValidateDateTime(const DateTime& time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
time.day < 1 || time.day > 31 ||
time.hour < 0 || time.hour > 23 ||
time.minute < 0 || time.minute > 59 ||
time.second < 0 || time.second > 59) {
return false;
}
if (time.month == 2 && IsLeapYear(time.year)) {
return time.month <= kDaysInMonth[time.month] + 1;
} else {
return time.month <= kDaysInMonth[time.month];
}
} 35
static const int kDaysInMonth[13] = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
bool ValidateDateTime(const DateTime& time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
time.day < 1 || time.day > 31 ||
time.hour < 0 || time.hour > 23 ||
time.minute < 0 || time.minute > 59 ||
time.second < 0 || time.second > 59) {
return false;
}
if (time.month == 2 && IsLeapYear(time.year)) {
return time.month <= kDaysInMonth[time.month] + 1;
} else {
return time.month <= kDaysInMonth[time.month];
}
} time.day
Error in the
protobuf project
(Chromium)
36
Safety Issues
• Innovations (IoT, Embedded)
• All-round measures:
• Coding standards
• Code coverage
• DAST
• SAST
Coding Standards
• Common Weakness Enumeration
• SEI CERT Coding Standards
• MISRA C, MISRA C++
• C++ Core Guidelines: https://github.com/isocpp/CppCoreGuidelines
SAST - Static Application Security Testing
Conclusion
• C and C++ are definitely worth learning
• The languages and related infrastructure are growing and
evolving
Questions
• PVS-Studio: https://www.viva64.com
• Contacts: Andrey Karpov, CTO, karpov@viva64.com
• Subscribe:
• vk.com: pvsstudio_rus
• Instagram: @pvs_studio_unicorn

Contenu connexe

Tendances

Dzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_PresentDzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_Present
Džanan Bajgorić
 
Assignment of pseudo code
Assignment of pseudo codeAssignment of pseudo code
Assignment of pseudo code
Burhan Chaudhry
 

Tendances (20)

Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the race
 
Nicety of java 8 multithreading for advanced, Max Voronoy
Nicety of java 8 multithreading for advanced, Max VoronoyNicety of java 8 multithreading for advanced, Max Voronoy
Nicety of java 8 multithreading for advanced, Max Voronoy
 
Interaksi obyek
Interaksi obyekInteraksi obyek
Interaksi obyek
 
C++: a fast tour of a fast language
C++: a fast tour of a fast languageC++: a fast tour of a fast language
C++: a fast tour of a fast language
 
Legacy projects: how to win the race
Legacy projects: how to win the raceLegacy projects: how to win the race
Legacy projects: how to win the race
 
OWC 2012 (Open Web Camp)
OWC 2012 (Open Web Camp)OWC 2012 (Open Web Camp)
OWC 2012 (Open Web Camp)
 
OpenGL L07-Skybox and Terrian
OpenGL L07-Skybox and TerrianOpenGL L07-Skybox and Terrian
OpenGL L07-Skybox and Terrian
 
Bab3of
Bab3ofBab3of
Bab3of
 
Using R in remote computer clusters
Using R in remote computer clustersUsing R in remote computer clusters
Using R in remote computer clusters
 
How to easily find the optimal solution without exhaustive search using Genet...
How to easily find the optimal solution without exhaustive search using Genet...How to easily find the optimal solution without exhaustive search using Genet...
How to easily find the optimal solution without exhaustive search using Genet...
 
R and cpp
R and cppR and cpp
R and cpp
 
JSON's big problem android_taipei_201709
JSON's big problem android_taipei_201709JSON's big problem android_taipei_201709
JSON's big problem android_taipei_201709
 
Dzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_PresentDzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_Present
 
Assignment of pseudo code
Assignment of pseudo codeAssignment of pseudo code
Assignment of pseudo code
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
 
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomersPyCon Ukraine 2016: Maintaining a high load Python project for newcomers
PyCon Ukraine 2016: Maintaining a high load Python project for newcomers
 
R and C++
R and C++R and C++
R and C++
 
C++ Coroutines
C++ CoroutinesC++ Coroutines
C++ Coroutines
 
A blast from the past
A blast from the pastA blast from the past
A blast from the past
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David Szakallas
 

Similaire à The Great and Mighty C++

Similaire à The Great and Mighty C++ (20)

SAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilitiesSAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilities
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
 
Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2Get together on getting more out of typescript &amp; angular 2
Get together on getting more out of typescript &amp; angular 2
 
Getting started with C++
Getting started with C++Getting started with C++
Getting started with C++
 
PVS-Studio in 2019
PVS-Studio in 2019PVS-Studio in 2019
PVS-Studio in 2019
 
PVS-Studio features overview (2020)
PVS-Studio features overview (2020)PVS-Studio features overview (2020)
PVS-Studio features overview (2020)
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
Living with Garbage by Gregg Donovan at LuceneSolr Revolution 2013
Living with Garbage by Gregg Donovan at LuceneSolr Revolution 2013Living with Garbage by Gregg Donovan at LuceneSolr Revolution 2013
Living with Garbage by Gregg Donovan at LuceneSolr Revolution 2013
 
Return of c++
Return of c++Return of c++
Return of c++
 
Living With Garbage
Living With GarbageLiving With Garbage
Living With Garbage
 
Living with garbage
Living with garbageLiving with garbage
Living with garbage
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 
Effective C++
Effective C++Effective C++
Effective C++
 

Plus de Andrey Karpov

Plus de 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
 
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
 
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOpsPVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
 

Dernier

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Dernier (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
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
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

The Great and Mighty C++

  • 1. The Great and Mighty C++ Andrey Karpov karpov@viva64.com
  • 2. www.reddit.com/r/programming • SVG Is Turing Complete • A step-by-step guide to analyzing JSON (and other semi-structured datasets) with SQL • “Performance Matters” by Emery Berger (Strange Loop 2019) • Why are large companies so difficult to rescue (regarding bad internal technology) • Practical Ways to Write Better Javascript • From UNIX to Linux, a time lapse of 45 years, Hendrik Jan Thomassen • Stack Overflow Trends – Scala's decline mirrors Kotlin's rise • Maximize learnings from a Kubernetes cluster failure • Why Go and not Rust? • Q&A: How Google Implements Code Coverage at Massive Scale • Hierarchical Instrumented Tracing with Logback • Court of appeals rules web scraping doesn't violate anti-hacking law - JavaScript Web Scraping Guy • Building GraphQL apis with Django
  • 3.
  • 4.
  • 5. Everyone Just Lives in Their Own Reality • С++ Russia x3 (Novosibirsk, Moscow, Saint Petersburg) • CoreHard (Minsk) • Meeting C++ (Berlin) • CppCon (Colorado) • C++Now (Colorado) • Italian C++ Conference (Milan) • emBO++ (Bochum) • ....
  • 6. Presenter: • Andrey Karpov, PhD in physics and math • Technical Director at SiProVer LLC • Microsoft MVP • Intel Black Belt Software Developer • One of the PVS-Studio project’s founders
  • 7. A Few Words About Us • We stand on guard of code quality. • PVS-Studio detects errors and potential vulnerabilities in С, C++, C# and Java code. • We actively participate in conferences, do conference talks, and write many articles dedicated to code quality.
  • 8. Are С and C++ alive? PDP Software Is! •The PDP-11 mini-computer
  • 9. Are С and C++ Alive? Even More, IBM RPG Is! •IBM RPG is a programming language whose syntax was initially similar to the command language of IBM’s mechanical tabulators. •Was widely used in 1960s and 1970s. IBM 1401
  • 10. C and C++ Are Not Just for Old Systems • C++ Applications - http://www.stroustrup.com/applications.html • Adobe Photoshop • Mozilla Firefox • Thunderbird • World of Warcraft • Apple – OS X • Chrome (Launch date: September 2, 2008)
  • 11. Are С and C++ Alive? • TIOBE Index: if you add up C and C++, C/C++ will be the leader.
  • 12. Summary for C, C++ • It’s a good idea to learn these languages • There are and there will be many jobs for C/C++ developers • The number of embedded systems in C is growing
  • 13. Topics: • Embedded systems • A few words about innovations • Development tool maturity and speeding up project builds • The safe programming trend • Various assistance tools that help control code quality
  • 14. Embedded: C and С++ Are on the Rise • Embedded • IoT (Internet of Things)
  • 15. Anticipated IoT Growth Rate 15.41 17.68 20.35 23.14 26.66 30.73 35.82 42.62 51.11 62.12 75.44 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 Источник: https://www.statista.com/statistics/471264/iot-number-of-connected-devices-worldwide/
  • 16. std::string • C++ Russia 2017: Anton Polukhin, What Not to Do: C++, How to Invent the Wheel Correctly (for Experts) https://youtu.be/rJWSSWYL83U (in Russian) • vstring • std::string
  • 17. C++17: 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 }
  • 18. C++17: init-statement in if and switch if (auto it = m.find(key); it != m.end()) { .... }
  • 19. C++17: A New Attribute [[fallthrough]] switch (i) { case 10: f1(); break; case 20: f2(); break; case 30: f3(); [[fallthrough]]; // The warning will be suppressed case 40: f4(); break; }
  • 20. C++17: A New Attribute [[nodiscard]] [[nodiscard]] int Sum(int a, int b) { return a + b; } int main() { Sum(5, 6); // A compiler/analyzer // will issue a warning return 0; }
  • 21. C++17: Fold Expressions template<typename... Args> auto Sum(Args... args) { return (args + ...); } int main() { std::cout << Sum(1, 2, 3, 4, 5) << 'n'; // 15 return 0; }
  • 22. С++17: Removed Features • Trigraphs were removed. • The register keyword cannot be used as a variable specifier anymore. • Prefix and postfix increment operators for type bool removed. • std::auto_ptr was removed. Use std::unique_ptr instead.
  • 23. С++17: And So On • I recommend an article by my colleague, Egor Bredikhin "C++17" https://www.viva64.com/en/b/0533/
  • 24. Speed up Your Project Build: Distributed Compilation • IncrediBuild - https://www.incredibuild.com/ • distcc - https://github.com/distcc/distcc • Icecream - https://github.com/icecc/icecream
  • 25. Speed up Your Project Build: Compiler Cache • When you compile a preprocessed file, a hash value is calculated based on the file’s contents, the compilation flags, and the compiler’s output. • When you recompile an unchanged file that has the same flags, the compiler retrieves a ready-made file from cache and feeds it to the linker.
  • 26. Speed up Your Project Build: Compiler Cache
  • 27. Speed up Your Project 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
  • 28. Speed up Your Project Build: More Information • See my colleague Phillip Khandeliants’s article "Speeding up the Build of C and C++ Projects" https://www.viva64.com/en/b/0549/
  • 29. A Tool’s Maturity Level • Compilers • Development environments • Dynamic analyzers • Static analyzers
  • 30. Dynamic Analyzers • Classic tools: • Valgrind • BoundsChecker • Intel Parallel Inspector • New from Google: • AddressSanitizer • ThreadSanitizer • MemorySanitizer
  • 31. Static Code Analyzers • Coverity • Klocwork • Parasoft • PVS-Studio • SonarQube • “Their name is Legion": List of tools for static code analysis https://en.wikipedia.org/wiki/List_of_tools_for_static_code_ analysis
  • 32. PVS-Studio • C, C++, C#, Java • Windows, Linux и macOS • https://www.viva64.com/ • Ways to Get a Free License https://www.viva64.com/en/b/0614/
  • 33. static const int kDaysInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; bool ValidateDateTime(const DateTime& time) { if (time.year < 1 || time.year > 9999 || time.month < 1 || time.month > 12 || time.day < 1 || time.day > 31 || time.hour < 0 || time.hour > 23 || time.minute < 0 || time.minute > 59 || time.second < 0 || time.second > 59) { return false; } if (time.month == 2 && IsLeapYear(time.year)) { return time.month <= kDaysInMonth[time.month] + 1; } else { return time.month <= kDaysInMonth[time.month]; } } 33
  • 34. static const int kDaysInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; bool ValidateDateTime(const DateTime& time) { if (time.year < 1 || time.year > 9999 || time.month < 1 || time.month > 12 || time.day < 1 || time.day > 31 || time.hour < 0 || time.hour > 23 || time.minute < 0 || time.minute > 59 || time.second < 0 || time.second > 59) { return false; } if (time.month == 2 && IsLeapYear(time.year)) { return time.month <= kDaysInMonth[time.month] + 1; } else { return time.month <= kDaysInMonth[time.month]; } } 34
  • 35. static const int kDaysInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; bool ValidateDateTime(const DateTime& time) { if (time.year < 1 || time.year > 9999 || time.month < 1 || time.month > 12 || time.day < 1 || time.day > 31 || time.hour < 0 || time.hour > 23 || time.minute < 0 || time.minute > 59 || time.second < 0 || time.second > 59) { return false; } if (time.month == 2 && IsLeapYear(time.year)) { return time.month <= kDaysInMonth[time.month] + 1; } else { return time.month <= kDaysInMonth[time.month]; } } 35
  • 36. static const int kDaysInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; bool ValidateDateTime(const DateTime& time) { if (time.year < 1 || time.year > 9999 || time.month < 1 || time.month > 12 || time.day < 1 || time.day > 31 || time.hour < 0 || time.hour > 23 || time.minute < 0 || time.minute > 59 || time.second < 0 || time.second > 59) { return false; } if (time.month == 2 && IsLeapYear(time.year)) { return time.month <= kDaysInMonth[time.month] + 1; } else { return time.month <= kDaysInMonth[time.month]; } } time.day Error in the protobuf project (Chromium) 36
  • 37. Safety Issues • Innovations (IoT, Embedded) • All-round measures: • Coding standards • Code coverage • DAST • SAST
  • 38. Coding Standards • Common Weakness Enumeration • SEI CERT Coding Standards • MISRA C, MISRA C++ • C++ Core Guidelines: https://github.com/isocpp/CppCoreGuidelines
  • 39. SAST - Static Application Security Testing
  • 40. Conclusion • C and C++ are definitely worth learning • The languages and related infrastructure are growing and evolving
  • 41. Questions • PVS-Studio: https://www.viva64.com • Contacts: Andrey Karpov, CTO, karpov@viva64.com • Subscribe: • vk.com: pvsstudio_rus • Instagram: @pvs_studio_unicorn