wiki:Developer/Coding/Compile-time_feature-conditioned_compilation

Compile-time feature-conditioned compilation

Compile-Time Conditional Code Features

Some RTEMS features are compile-time dependent and normally can be enabled/disabled via RTEMS build configuration options, for example --enable-smp, --enable-networking, --enable-profiling, etc. There usually exists a C pre-processor symbol which is defined in case the feature is enabled, e.g. RTEMS_SMP, RTEMS_NETWORKING, RTEMS_PROFILING, etc. To limit the scope scattered with conditional compilation based on these feature defines the following rules should be followed:

  • Use inline functions which evaluate to empty bodies whenever possible.
  • Use "(void) arg;" to silence unused parameter warnings.

This provides type checks for the function calls even in case the feature is disabled. The compiler can easily optimize empty inline functions away. Example:

static inline feature_x_func(int a, double b, void *c) { #ifdef FEATURE_X

/* Do something */

#else

(void) a; (void) b; (void) c;

#endif }

Last modified on 05/30/14 at 17:25:57 Last modified on 05/30/14 17:25:57