wiki:Developer/Coding/Compile-time_feature-conditioned_compilation

Version 1 (modified by Gedare, on May 30, 2014 at 5:25:57 PM) (diff)

Created page with "==Compile-Time Conditional Code Features== Some RTEMS features are compile-time dependent and normally can be enabled/disabled via RTEMS build configuration options, for examp..."

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 }