Avoid if Possible

  • Using void * because this generally means that one must using casting, and in C++ casting is rather ugly. It is OK to use void * to pass structure address where the structure is not known to the routines accepting the packet (typically callback routines). However, declaring void *buf is 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, and uint64_t). This guarantees that the variables are given exactly the size you want. Please try at all possible to avoid using size_t ssize_t and 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_MEM instead.

  • Templates – they can create portability problems.

  • Fancy or tricky C or C++ 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)

Possible Next Steps

Go to Do Use Whenever Possible.

Go back to Developer Notes.

Go back to Developer Guide.