Pass and return primitives as value to and from functions [Breymann] p177 ,[Davis]
Pass objects as const reference to functions and omit const
only when the function is designed to modify the object [Breymann] p177
Return objects which are attributes of the class as const reference and objects wich are
not class attributes (especially stack and heap
objects) as value! [Breymann] p177
Prefer references to pointers. References (and reference types) are just syntactic sugar for pointers and do not cause runtime overhead [Breymann?], [Quiroz]
To avoid memory leaks encapsulate new
and delete
in the constructor and destructor of a class. Than create the instance of the class as automatic variable. [?]
Always declare constant primitives and objects with const
int
is the most efficient type for local variables. (No filling with zero's necessary) [Davis]
Use stdint.h
. It offers… [Davis]
Larger data types as int
are less efficient [Davis]
Use the size_t
and ptdiff_t
types for memory calculations, not the long
type [Davis]
Unsigned types tend to be more efficient then signed [Davis]
Plain char
is always the most efficient char type. For signed or unsigned char it depends on the target which one is more efficient. [Davis]
Declare global data and functions as static
whenever possible but avoid static
variables at function level whenever possible [Davis]
Use the
restrict
keyword for data that is modified by one certain pointer [Davis]
Declare variables in the innermost scope possible [Davis]
Prefer float types to double (Use 3.0f
instead of 3.0
and sinf()
instead of sin()
) [Davis]
It most often more efficient to use the stack rather than the heap for variable length arrays.
Expamle! [Davis]
Declare a function as inline when it is… [Davis]
Use a mutex
for concurrent data access [Obiltschnig]
Do not use exceptions in realtime / embedded systems. They may have non-deterministic runtime behauviour. Use
goto as alternative. [Obiltschnig], [Quiroz]
Use consts rather than preprocessor defines [Quiroz]
To avoid name collisions use namespaces rather than prefixes or classes [Quiroz]
Aviod Run-Time Type Identification (RTTI) at least for realtime / embedded systems [Quiroz]