Empty inline functions vs. empty CPP macros

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Mar 11 08:47:56 UTC 2014


Hello,

I would like to add a new section to the RTEMS coding style.  How do we want to 
deal with features available only in case certain pre-processor symbols are 
defined?  For example

#define FEATURE_X

1:

static inline feature_x_func(int a, double b, void *c)
{
#ifdef FEATURE_X
   /* Do something */
#else
   (void) a;
   (void) b;
   (void) c;
#endif
}

2:

#ifdef FEATRUE_X
static inline feature_x_func(int a, double b, void *c)
{
   /* Do something */
}
#else
#define feature_x_func(a, b, c) do { } while ( 0 )
#endif

3:

#ifdef FEATRUE_X
static inline feature_x_func(int a, double b, void *c)
{
   /* Do something */
}
#else
#define feature_x_func(a, b, c) \
   do { (void) *a); (void) (b); (void) (c); } while ( 0 )
#endif

I am in favor of variant 1. since it has the benefit that type checks are also 
performed in case feature X is disabled.

Is the optimization of an empty inline function really a problem for modern 
compilers?

In 2. we could also use an (for basedefs.h)

#define RTEMS_EMTPY_MACRO do { } while ( 0 )

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the devel mailing list