Avoid if Possible
CommunityUsing void * because this generally means that one must using casting, and in
C++casting is rather ugly. It is OK to usevoid *to pass structure address where the structure is not known to the routines accepting the packet (typically callback routines). However, declaringvoid *bufis a bad idea. Please use the correct types whenever possible.Using undefined storage specifications such as (
short,int,long,long long,size_t…). The problem with all these is that the number of bytes they allocate depends on the compiler and the system. Instead use Bacula’s types (int8_t,uint8_t,int32_t,uint32_t,int64_t, anduint64_t). This guarantees that the variables are given exactly the size you want. Please try at all possible to avoid usingsize_t ssize_tand the such. They are very system dependent. However, some system routines may need them, so their use is often unavoidable.Returning a malloc’ed buffer from a subroutine – someone will forget to release it.
Heap allocation (malloc) unless needed – it is expensive. Use
POOL_MEMinstead.Templates – they can create portability problems.
Fancy or tricky
CorC++code, unless you give a good explanation of why you used it.Too much inheritance – it can complicate the code, and make reading it difficult (unless you are in love with colons)
See also
Previous articles:
Next articles:
Go back to: Developer Notes.