C++ coding style

The coding style of mcdecoder in C++ is based on Google C++ Style Guide. The mcdecoder adds some modifications to it because some codes in mcdecoder are generated by a tool.

Exceptions to the rule

Naming

For type names, constant names, function names and enumerator names:

This project

You can use underscores to split the base part and the generated part: <base>_<generated>. The generated part is optional.

Examples:

  • Type: DecodeRequest, DecodeResult_add, etc.

  • Constant: kInstructionIdMax, kDecodeErrorsMax, etc.

  • Function: DecodeInstruction, PrintInstruction_add, etc.

  • Enumeration type: InstructionId, DecodeErrors_add, etc.

  • Enumerator: kUnknown, k_add, etc.

Original

With no underscores.

Rationale

To clarify the boundary between the fixed part and the generated part of a type name, we put underscore symbol between them.

You can see also the original ‘Naming’.

Comments / Comment Style

This project

Use /** */ in API comments and // for others.

Original

You can use either the // or the /* */ syntax. Be consistent with how you comment and what style you use where.

Rationale

For API comments for Doxygen, /** */ is much more common and you can tell the difference between API comments and other comments more easily.

You can see also the original ‘Comments / Comment Style’.