features.h: Feature Test Macros

With which C standard (C89, C99, C11, etc.) you are compiling your code decides which features are available. For example, pthread-barriers are not present under C99. If you come across a scenario when the compiler fires an error saying something is not defined, even though, it seems to be present in the included header, then probably it is because some how that definition was excluded by the preprocessor because the feature is disabled. To properly enable particular feature, we needed to define appropriate macros that are present in features.h.

Continue reading “features.h: Feature Test Macros”

The Daemon Pattern

This is a common pattern seen in daemons (in C like languages).

int some_func()
     struct foo_s *foo = (struct foo_s *) malloc(sizeof(struct foo_s));
     while (1) {

     return r;
 Courtsey: pacman.wikia.com

The unreachable free() makes no sense. A missing free(), though unreachable, annoys a purist. Considering the scope and visibility of foo(), putting it on the heap is not the best approach. The scope is within some_func(), and the visibility is until the process exits (killed).

Continue reading “The Daemon Pattern”