Open Eggbert

C++

This article is devoted to collect content about the C++ programming language.

C++ is programming language created in 1985 by Bjarne Stroustrup.

C++ is based on the C programming language. OOP in C++ was inspired by the Simula67 programming language. Almost all C programs are valid C++ programs.

The name of the C++ programming language is related to the incremental operator "++" and was created by Rick Mascitti in Summer 1983 and was first used in December 1983.

The C++ predecessor is "C with Classes", which is an extension of the C programming language created by Bjarne Stroustup in 1979.

Reason for creation of C++: To make the programming easier without the usage or assembler or C or other programming languages.

Advantages: Programming paradigms supported by C++: C++ remains one of the most powerful and versatile programming languages. Key Features of C++: Common Applications of C++: Modern C++ and Future Trends: Modern C++ focuses on improving developer productivity while maintaining backward compatibility. Recent updates have introduced concepts, coroutines, modules, and ranges to simplify development. The future of C++ is expected to bring better safety, concurrency, and performance enhancements, keeping it relevant for decades to come.

Comparison of C++ and C

The following are examples of additional features in C++ compared to C:

How to create a C++ program

creating the C++ source code (text files), compiling to object files, linking object files to an executable version of the program.

File name extensions of C++ source code file

Implementation of C++ File name extensions
UNIX C, cc, cxx, c
GNU C++ C, cc, cxx, cpp, c++
Microsoft Visual C++ cpp, cxx, cc

Other

How to manage memory automatically: Boehm-Demers-Weiser Garbage Collector

Functions

C++ program consists of functions. Function consists of statements. Each statement must end with the semicolon character. Prototype vs implementation.

Function main()

Function main() is the entrypoint of an C++ application.

Variants:

Console

How to delay program and wait for the press of the key Enter: cin.get();
Printing text to console: cout << "some text"; //operator overloading: <<
Reading text from console: cin >> carrots;
How to print end line: "\n" or std::endl

Comments

One line: // comment
Multi line: /* comment */

Preprocessor directives

#include <iostream>

Includes file iostream

#define INT_MAX 32767

Replaces all INT_MAX occurences by 32767

Importing namespaces

using namespace std;
using std::count;

C++ statement

Each C++ statement must be ended with the semicolon character ;

Declaration (statement type)

This allocates memory.
Example: int carrots;

Assignment (statement type)

Example: carrots 15;

Initialization (statement type)

int carrots 15;
//or
int carrots (15);

Key words

return, void, int, const And others

Constexpr

The constexpr keyword in C++ is used to define constants that are evaluated at compile time, ensuring optimized and predictable behavior.
It can gives performance boost.

Variable

Variable is named location in the memory with its type definition.
You can get the location in the memory with the & operator.

Data types

Void

Empty set of values, cannot be used as the type of variable.

Integral

short: at least 16 bits
int: at least the same size as short (since -32768 until 32 767)
long: at least 32 bits, at least the same size as int
long long (since C++ 99): at least 64 bits, at least the same size as long
unsigned: unsigned short, unsigned int, unsigned long, unsigned long long
Octal: starts with 0
Hexadecimal: starts with 0x or 0X
char
wchar_t
bool

Floating-point

Combined data types

Operators

sizeof

Class

Class is user defined type]

Integrated development environments for C++

Visual Studio

Visual Studio is an integrated development environment developed by the Microsoft company and it is a closed-source- and proprietary software.
For development of Windows Phone 8, 8.1 or 10.0 applications Visual Studio 2015 is used.
For development of Windows Phone 7, 7.1 applications Visual Studio 2010 or Visual Studio 2012 is used.

C++ Compilers

External link: https://en.wikipedia.org/wiki/Category:C%2B%2B_compilers

Cfront

The first compiler was Cfront created by Bjarne Stroustrup in 1983.
Cfront converted C++ code into C, but the resulting output was not easily readable or understandable by humans. Later, new C++ compilers were created. These compilers converted C++ directly to the machine code.

GCC

Clang

Microsoft Visual C++

C++ Decompilers

Ghidra

Books: https://www.amazon.com/Ghidra-Book-Definitive-Guide/dp/1718501021

IDA

https://hex-rays.com/decompiler

C++ Disassemblers

https://en.wikipedia.org/wiki/List_of_disassemblers
https://en.wikipedia.org/wiki/Disassembler

Ghidra

Ghidra is an Disassembler and Decompiler developed by NSA and later published as a free and opensource software.

IDA Free

IDA is the free version has the limited set of features

Objdump

objdump is the part of GNU binutils

How to convert a x86 exe file to the Assembly language

objdump -D -M intel your_file.exe > output.asm -D means to disassembly the whole file
-M intel sets the format of the assembly to Intel

Steps to Create an Executable Program in C++

  1. Create the C++ source code in any text editor.
    This step is done by the programmer (human).
  2. Convert the C++ source code to object code (machine language).
    This step is done by the compiler.
  3. Link the object code with libraries.
    The result is an executable program. This step is done by the linker.

History of C++ Standardization

1990

The work on the standardization of C++ started in 1990 by ANSI/ISO.

1991–1997

During the following years, several working drafts of the C++ standard were published.

Before 1998

Before official standardization, many people recognized the latest versions of C++ published by Bell Labs as the de facto standard.

1998

The first official standard of C++ was published and is known as C++98.

The Future of C++: 10, 100, and 1000 Years Ahead

The Next 10 Years: Evolution and Adaptation

In the short term, C++ will continue evolving with regular standard updates every three years. The upcoming C++26 and C++29 are expected to refine the language further, focusing on:

The Next 100 Years: The Role of C++ in a Post-Classical Computing Era

As computing paradigms shift, C++ will need to adapt to entirely new architectures. Some potential transformations include:

The Next 1000 Years: The Legacy of C++ in a Post-Human World

Predicting the state of technology 1000 years into the future is speculative, but here are some possibilities for C++'s long-term role:

Conclusion

C++ has continuously adapted over the past 40+ years, and there is no reason to believe it won’t continue evolving for the next millennium. Whether through performance optimizations, new computing paradigms, or AI-driven development, C++ is poised to remain one of the most influential languages far into the future. While it may not exist in its current form in 1000 years, its principles of efficiency, flexibility, and control over hardware will likely shape the foundation of future computing.

Performance Comparison: Reimplementing a 2D Platformer (C++/DirectX 3 to Java/LibGDX)

1. Language Differences (C++ vs. Java)

2. Graphics Libraries (DirectX 3 vs. LibGDX)

3. Platform Performance

4. Memory Management

5. Rendering and FPS

Conclusion

The performance of a Java/LibGDX implementation may be slightly worse than the original C++/DirectX 3 version due to:

That said, for modern hardware and a well-written Java implementation, the performance difference should be negligible for a simple 2D platformer. Furthermore, the cross-platform support offered by LibGDX is a significant advantage that can outweigh minor performance trade-offs.

Testing

There are several tools for testing C++ programs:

Books