Coding Style

From NetXMS Wiki
Revision as of 23:52, 22 February 2012 by Victor (talk | contribs) (Created page with "= Coding style for C and C++ = 1. Function names: each word in function name should start with capital letter. No underscores. For example: '''CreateNewUser'''. Underscores a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Coding style for C and C++

1. Function names: each word in function name should start with capital letter. No underscores. For example: CreateNewUser. Underscores allowed in parameter handlers, which can start with H_ prefix, like this: H_FreeDiskSpace.

2. Class names: each word in class name should start with capital letter. No underscores. For example: NetworkService.

3. Class methods: each word in methos name should start with capital letter, except first word. No underscores. For example: NetworkService::createService().

4. Class members: name must start with m_ prefix, each word in member name should start with capital letter, except first word. No underscores. For example: NetworkService::m_serviceId.

5. Indentation offset: 3

6. Opening { should be placed on next line without indentation, like below:

  if (a < b)
  {
     something();
  }

7. Operators and operands should be separated by spaces, like below:

  a = x + 20 / (y - z);

8. Function arguments should be separated by spaces, like below:

  z = function(p1, p2, p3);

9. One-line comments should be placed with the same indentation level as code, like this:

  c = xxx();
  if (a)
  {
     // comment
     func();
  }

10. Brackets after for and while operators may or may not be separated by spaces (I prefer not to separate them, but it's not a big problem IMHO).

11. For type cast type name must be enclosed in brackets, without spaces. For example: (DWORD)x.

12. It is recommended to use the dollowing typedefs as a replacement for some system data types:

WORD unsigned short (16 bit unsigned integer)
LONG instead of system's 32 signed integer
DWORD unsigned long (32 bit unsigned integer)
INT64 instead of system's 64 bit signed integer
QWORD instead of system's 64 bit unsigned integer