An inheriting class with a user-defined copy constructor must call its base class's copy constructor.
Fall-through in switch cases is often considered risky.
Hence consider adding an unconditional break
for each switch clause.
sizeof()
in memory allocation CXX-S1006The malloc
function usually expects a memory size value in units (usually byte
)
when allocating any type. Use sizeof(type) * number_of_values
as the size argument
for malloc
to avoid making mistakes.
float
to double
in a math function CXX-P2001Calling math functions that only accept double
with float
arguments
causes an implicit type promotion of float
argument.
Type promoting float
to double
costs extra space in memory, it also costs extra
instructions for the conversion from float
and lastly vectorisation of float
is a lot more efficient compared to double
.
Pointer offset(or any other arithmetic operation) on a pointer casted to a different type (than its original type) is risky and can result in undefined behaviour. The reason for such behaviour is that the memory alignment may change for types on every targeted platform.