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.