C++ For C# Developers: Part 1 – Introduction
Outside of Unity, C# is rarely used as a game programming language. C++ is used heavily in Unreal, Cryengine, Lumberyard, and almost all proprietary game studio engines. This series is for Unity game programmers who know C# and want to broaden their skills so they can effectively write code for other engines, or even write C++ scripts for Unity. Today we’ll begin with an introduction to C++’s history, standard library, tools, community, and documentation. Read on to get started!
Table of Contents
- Part 1: Introduction
- Part 2: Primitive Types and Literals
- Part 3: Variables and Initialization
- Part 4: Functions
- Part 5: Build Model
- Part 6: Control Flow
- Part 7: Pointers, Arrays, and Strings
- Part 8: References
- Part 9: Enumerations
- Part 10: Struct Basics
- Part 11: Struct Functions
- Part 12: Constructors and Destructors
- Part 13: Initialization
- Part 14: Inheritance
- Part 15: Struct and Class Permissions
- Part 16: Struct and Class Wrapup
- Part 17: Namespaces
- Part 18: Exceptions
- Part 19: Dynamic Allocation
- Part 20: Implicit Type Conversion
- Part 21: Casting and RTTI
- Part 22: Lambdas
- Part 23: Compile-Time Programming
- Part 24: Preprocessor
- Part 25: Intro to Templates
- Part 26: Template Parameters
- Part 27: Template Deduction and Specialization
- Part 28: Variadic Templates
- Part 29: Template Constraints
- Part 30: Type Aliases
- Part 31: Deconstructing and Attributes
- Part 32: Thread-Local Storage and Volatile
- Part 33: Alignment, Assembly, and Language Linkage
- Part 34: Fold Expressions and Elaborated Type Specifiers
- Part 35: Modules, The New Build Model
- Part 36: Coroutines
- Part 37: Missing Language Features
- Part 38: C Standard Library
- Part 39: Language Support Library
- Part 40: Utilities Library
- Part 41: System Integration Library
- Part 42: Numbers Library
- Part 43: Threading Library
- Part 44: Strings Library
- Part 45: Array Containers Library
- Part 46: Other Containers Library
- Part 47: Containers Library Wrapup
- Part 48: Algorithms Library
- Part 49: Ranges and Parallel Algorithms
- Part 50: I/O Library
- Part 51: Missing Library Features
- Part 52: Idioms and Best Practices
- Part 53: Conclusion
History
C++’s predecessor is C, which debuted in 1972. It is still the most used language with C++ in fourth place and C# in fifth.
C++ got started with the name “C with Classes” in 1979. The name C++ came later in 1982. The original C++ compiler, Cfront, output C source files which were then compiled to machine code. That compiler has long since been replaced and modern compilers all compile C++ directly to machine code.
Major additions to the language were added with “C++ 2.0” in 1989 and the language was then standardized by ISO in 1998. Colloquially, this was called C++98 and began the convention where the year is added to name a version of the language. It also formalized the process of designing and standardizing the language via a committee and various working groups.
Minor changes to the language in 2003 resulted in C++03, but the “Modern C++” era began with huge changes to the language in C++11. This also quickened the standardization process from the previous eight year gap to just three years. This meant that we got minor changes in C++14, relatively big changes in C++17, and huge changes are about to be released in C++20. Game engines such as Unreal, Cryengine, and Lumberyard all support the latest version—C++17—and will likely support C++20 after it is standardized.
At this point the language has little resemblance to C. Much C code will still compile as C++, but idiomatic C++ is only superficially similar to C.
Standard Library
Every release of C++ includes what is called the “Standard Library.” This is often called the “STL,” meaning “Standard Template Library,” for its heavy use of a C++ language feature called templates. This library is also standardized by ISO along with the language itself.
The Standard Library is similar to .NET’s Framework Class Library or CoreFX. The architectural approach is for the C++ language to have powerful, low-level language features so more can be implemented in libraries instead of directly included in the language. For example, the language doesn’t include a string class. Instead, the Standard Library provides a string
class that is efficiently implemented with low-level language features.
The following table shows the major sections of the Standard Library and their loose equivalents in .NET:
Standard Library Section | C++ | C# |
---|---|---|
Language support | numeric_limits |
int.MaxValue |
Concepts | default_initializable |
where T : new() |
Diagnostics | exception |
System.Exception |
Utilities | tuple<int, float> |
(int, float) |
Strings | string |
System.String |
Containers | vector |
List |
Iterators | begin() |
GetEnumerator() |
Ranges | views::filter |
Enumerable.Where |
Algorithms | transform |
Enumerable.Select |
Numerics | accumulate |
Enumerable.Aggregate |
Localization | toupper |
Char.ToUpper |
I/O | fstream |
FileStream |
File system | copy |
File.Copy |
Regular expressions | regex |
Regex |
Atomic operations | atomic |
Interlocked.Increment |
Threading | thread |
Thread |
Some game programming environments do not use the Standard Library, or at least minimize its use. EA has implemented their own version called EASTL. Unreal has many built-in similar types (FString
vs. string
) and functions (MakeUnique
vs. make_unique
). These libraries benefit from the same low-level language features that the Standard Library is built on, but instead use them to efficiently reimplement what would be language features in many other languages.
Tools
The main tool is, of course, the compiler. There are many good options these days, but here are some of the most popular ones:
Compiler | Cost | Open Source | Platforms |
---|---|---|---|
Microsoft Visual Studio | Free and Paid | No | Windows |
GCC (GNU Compiler Collection) | Free | Yes | Windows, macOS, Linux |
Clang | Free | Yes | Windows, macOS, Linux |
Intel C++ | Free | No | Windows, macOS, Linux |
There are also many IDEs available with the usual combination of features: a text editor, compiler execution, interactive debugger, etc. Here are some popular options:
IDE | Cost | Open Source | Platforms |
---|---|---|---|
Microsoft Visual Studio | Free and Paid | No | Windows |
Apple Xcode | Free | No | macOS |
JetBrains CLion | Paid | No | Windows, macOS, Linux |
Microsoft Visual Studio Code | Free | Yes | Windows, macOS, Linux |
Many static analyzers, known as “linters,” and dynamic analyzers are available. The Clang sanitizers suite is free, open source, and has Unreal support. Commercial tools such as Coverity SAST are also available. Clang format and many IDEs can enforce style guides and automatically reformat code.
Documentation
The C++ standard is available for purchase, but almost no C++ developers actually buy it. A draft version is available for free and will be nearly identical, but it is extremely long and technical so it is also only a reference of last resort. Instead of the standard itself, most developers read reference sites such as cppreference.com just as they would read Microsoft Docs (a.k.a. MSDN) for C# reference.
Many guideline documents exist for C++. The C++ Core Guidelines, Google C++ style guide, and engine-specific standards are all commonly used. The C++ Core Guidelines, in particular, has a companion Guidelines Support Library (GSL) to enforce and facilitate the guidelines.
Community
There are many places where the community of developers congregate. Here are a few:
- The C++ language Slack has 16,000 members
- The /r/cpp subreddit has 136,000 members
- The /r/Cplusplus subreddit has 21,000 members
- CppCon is held annually and posts hundreds of talks
- Engine-specific forums are generally very active
- Many C++ GitHub repositories have 10,000+ stars and active Issues sections
Next
With this introduction out of the way, next week we’ll dive into the language itself and start learning how to program in C++!
#1 by SH42913 on May 18th, 2020 ·
Thanks for your article! Can’t wait for continue! :3
#2 by Wojtek on May 18th, 2020 ·
Great idea, looking forward to following this closely!
#3 by Maciej on May 18th, 2020 ·
I’m just curious about upcoming C++ articles – are you going to make them Unreal Engine – oriented , comparison to C# or rather general course C++ in game development ?
#4 by jackson on May 18th, 2020 ·
The series isn’t specific to Unreal or any other engine. That said, as in this article, I may occasionally call out engine-specific details.
#5 by MQuy on May 18th, 2020 ·
Love your talent & enthusiasm!
#6 by Vinicius Jarina on June 16th, 2020 ·
I guess the right comparison on compilers would be Roslyn , which is Open Source https://github.com/dotnet/roslyn and MIT licensed.
#7 by jackson on June 16th, 2020 ·
The article doesn’t compare compilers between the two languages, but if it did Roslyn would definitely be on that list along with Mono and Burst. Some IDE comparisons would include Visual Studio, Rider, and Visual Studio Code.
#8 by Juriy on July 20th, 2020 ·
Hi! First of all thank you for such a great series , but there’s a little thing which breaks the readability: most of tables here are shown as raw HTML code. I tried different browsers and result was the same. Am I missing a point or something is really broken?
https://imgur.com/SnvpX7y
#9 by Juriy on July 20th, 2020 ·
EDIT: the screenshot was taken from the 2nd part of the tutorial, 2nd table
#10 by jackson on July 20th, 2020 ·
Thanks so much for pointing this out! It was actually a problem on several articles in the series, so I went through and fixed them all.
#11 by Etherlord on July 27th, 2020 ·
Thanks for the article!
The table with C# and C++ comparison has escaped (double escaped) greater than and lesser than symbols as well as one enclosing tag.
#12 by jackson on July 27th, 2020 ·
You’re welcome! And thanks for pointing out the formatting issue. I’ve updated the article with a fix.
#13 by Jim on June 3rd, 2021 ·
This has been a great series. I learned a lot. I used C for everything years ago and then ended up using VB on windows and now C#. I had started C++ in the late 80s but switched groups and was on windows instead of unix. Anyway, your series filled in a lot of missing information for me. Thanks!
#14 by Sergio on July 17th, 2021 ·
Thank you!! Exactly what I need.
#15 by George on December 19th, 2021 ·
Heaven!
#16 by Fedor on February 9th, 2022 ·
That’s what I need!
#17 by You have 1 message # 416. Read - https://telegra.ph/Go-to-your-personal-cabinet-08-25?hs=64b73ef004f05b5c4f533c18b1081354& on September 29th, 2024 ·
w606bu