# Linux Kernel Module Cheat

#### 27.3.3. C++ initialization types

OMG this is hell, understand when primitive variables are initialized or not:

- https://stackoverflow.com/questions/3127454/how-do-c-class-members-get-initialized-if-i-dont-do-it-explicitly

- https://blog.tartanllama.xyz/initialization-is-bonkers/

Intuition:

- direct initialization: a constructor called explicitly with at least one argument: https://en.cppreference.com/w/cpp/language/direct_initialization

- default initialization: does not initialize primitive types: https://en.cppreference.com/w/cpp/language/default_initialization

- value initialization: maybe initializes primitive types: https://en.cppreference.com/w/cpp/language/value_initialization

- zero initialization: initializes primitive types

Good rule:

- initialize every single variable explicitly to prevent the risk of having uninitialized variables due to programmer error (which is easy to get wrong due to insane rules)

- if you don’t define your own default constructor, always `= delete` it instead. This prevents the possibility that variables will be assigned twice due to zero initialization