Skip to content

Latest commit

 

History

History
124 lines (121 loc) · 2.47 KB

File metadata and controls

124 lines (121 loc) · 2.47 KB

blam C++ conventions


  1. safe C practices should generally be preferred over modern C++

  1. perform static and runtime assertions where possible, i.e: array bounds, pointers, sizes

  1. everything_is_in_snake_case_and_verbose
long structure_bsp_index;

  1. typedef is deprecated, prefer using statements with names that have no prefix (try not to use these)
using real = float; // correct

typedef float real; // deprecated

  1. mutable global variable names start with g_
extern s_object_type_definition g_object_type_definitions[];

  1. enum and enum class names start with e_
enum e_cache_file_shared_type;

  1. struct names start with s_
struct s_tag_reference;

  1. class names start with c_
class c_cache_file_reader;

  1. const global variable names and enum capacity members start with k_
enum e_field_type
{
    _field_tag,
    // ...
    _field_terminator,
    k_number_of_field_types
};

  1. struct and class fields are each declared on their own lines
struct s_real_point3d
{
    real x;
    real y;
    real z;
};

  1. datatype classes should be explicitly declared final
class c_datum_handle final
{
private:
    long m_value;

public:
    // ...
};

  1. pure-virtual classes should explicitly declare novtable
class __declspec(novtable) c_cache_file_metadata_and_fixup_loader
{
public:
    virtual bool load_metadata_and_fixup(...) = 0;
};

  1. function parameters are each declared on their own line
bool tag_interop_fixup_manual_for_cache(
    s_tag_interop *interop_object,
    long cache_file_type_index,
    c_aligned_allocator *allocator,
    c_cache_file_fixup_verifier *verifier);

  1. curly braces always go on their own line
// wrong:
void do_something_wrong() {
    // oh no!
}

// correct:
void do_something_right()
{
    // oh yea!
}

  1. header files (.h) are divided into the following sections:
/* ---------- constants */
/* ---------- macros */
/* ---------- types */
/* ---------- classes */
/* ---------- globals */
/* ---------- prototypes */

  1. source files (.cpp) are divided into the following sections:
/* ---------- private constants */
/* ---------- private macros */
/* ---------- private types */
/* ---------- private classes */
/* ---------- globals */
/* ---------- private prototypes */
/* ---------- public code */
/* ---------- private code */