ccpp concepts - cbranton/computer-system-concepts GitHub Wiki

C++ concepts

C++ was designed to be efficient like C, but more conducive to developing large systems. Primary among the features added to this end was support for object-oriented features. C++ is not strictly object-oriented. It has often been described as "object-friendly".

C is C++ (for the most part)

Adoption is an important consideration when designing any langauge. Since C++ was hoping to expand an existing codebase, it was designed to run C unaltered. In other words, a legal C program is a legal C++ program. There are some minor exceptions to this rule[^1], but you can rely on it for the most part.

[^1]: One often cited exception is the use of C++ keywords in C programs. For example int new = 1 is legal C but not legal C++.

To compile C++ using the GNU compiler, replace gcc with g++. (See the Hello World example below.)

1 Hello world

Let's start by adapting our first C program to C++.

hello.cpp

// A first program in C++
#include <iostream>

int main ()
{
    // The std:: may be omitted by including "using namespace std" above
    std::cout << "Hello World!" << std::endl;
    return 0;
}

We have already discovered one of the differences with C++, namely stream input and output. std::cout is the C++ designation of the standard output stream. (Somewhat confusingly here, the std in std::out denotes the C++ standard library, not the standard output.) The << operator places the string on the output stream. The std::endl is a platform-independent newline marker. In most cases it will be equivalent to '\n')

Command line compiling with g++

Compiling and executing a C++ program is generally the same as with C. For example:

g++ -o hello hello.cpp
g++ -S -masm=intel hello.cpp

The first form above compiles hello.cpp into a file called hello. The second creates assembly langauge output in hello.s.

Hello with params

Bits and Bytes

Classes and objects

Pointers

Which means memory should probably move up here.

Files

File pointers and file descriptors

FILE object. <cstdio>

FILE

File pointer -- example file struct

typedef struct _iobuf
{
    char*   _ptr;
    int _cnt;
    char*   _base;
    int _flag;
    int _file;
    int _charbuf;
    int _bufsiz;
    char*   _tmpfname;
} FILE;

Memory and allocation

std::system()

Requests the command processor to execute a command

Appendix Setup

Using MacOS

Setting Up WSL

Configure SSH if you wish to use CLion

Using JetBrains CLion

https://www.jetbrains.com/help/clion/quick-tutorial-on-configuring-clion-on-windows.html

⚠️ **GitHub.com Fallback** ⚠️