Skip to content

Other improvements

Inline variables

can be used in header files which are used by multiple CPP files. All will refer to the same instance of the variable.

class MyCLass
{
    static inline int s_counter = 0;
};
inline MyClass myDefaultInstance;

Small improvements

  • volatile
    to be used for values which can be changed outside of the control of the program (e.g. by a signal handler). The compiler has to perform explicit load/store operations when reading/writing the value without the possibility of optimization. This has nothing to do with MultiThreading!
    volatile int myVolatileGlobalVariable;
    void DoSomething(volatile SomeStruct* in_pStruct);
  • char8_t
    can represent any UTF-8 code unit, has size 1 byte (like unsigned char) but is a different type
    std::u8string myUtf8String = u8"This is the String";
  • enum in local scopes
    enum class Color {RED, GREEN, BLUE};
    ...
    switch (color)
    {
    using enum Color;
    case RED: ... // here it is not necessary to specify the name "Color"
    case GREEN:

    ...