Style Guide/Best Practice C Cpp

= Best Practice =

Note that this page is in addition to the style guide which covers stylistic aspects of writing code, this page covers other topics relating to writing code for Blender.

Order of Operations for "sizeof(..)"
When calculating the size of a value in bytes, order sizeof first, eg: sizeof(type) * length, this avoids integer overflow errors by promoting the second value to size_t in the case it's a smaller type such as an int.

Note that for array allocation, we have MEM_malloc_arrayN and MEM_calloc_arrayN.

Comment unused arguments in C++ code
When a C++ function has an unused argument, prefer declaring it like int /*my_unused_var*/ to using the UNUSED macro. This is because the macro does not work properly for MSVC-- it only prevents using the variable but does not suppress the warning. It also has a more complex implementation.