Jun 20, 2022

[C++] ODR notes

ODR:
https://eel.is/c++draft/basic.def.odr


All definition across the program should be the same.

It's hard.


e.g.

// size of Person might be different inside the program.
class Person{
    std::string first_;
    std::string last_;
# if HAS_MIDDLE_NAME(VAR)
    std::string middle_;
#endif
};

ODRV can be embedded anywhere(DSO, static library, or executable)

  1. Multiple, conflicting definitions of the same symbol in more than one TU.
  2. Compiling a given header/source file with different compiler settings or #defines
    Debug/Release, (no-)RTTI, mismatched preprocessor values, etc.
  3. Overriding operator new/delete in a DSO, but hiding it from the rest of the program.
    The passing C++ objects across that DSO boundary.
  4. Multple varying copies of a dependency(e.g. Boost, JPEG, zlib, etc.)


ODRV Behaviors

  1. Hard to debug
  2. Hard to reproduce
  3. Exceptions failing to get caught
  4. Crashing in the destructor after passing an object across a DSO boundary.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.