On 21/08/2012 5:08 p.m., Kinkie wrote:
Hi all,
   as I'm refactoring things around (currently hacking protos.h to
pieces), I often encounter constructs such as:

.h file:
#if OPTIONAL_FEATURE
extern void someFunction();
#endif

.cc file:
#if OPTIONAL_FEATURE
void someFunction() {
   //code
}
#endif

client code:
#if OPTIONAL_FEATURE
   someFunction(arg);
#endif


I'm wondering if it wouldn't be more readable to transform this pattern into:
.h file:
extern void someFunction();

.cc file:
#if OPTIONAL_FEATURE
void someFunction() {
   //code
}
#else
void someFunction() {
   nop(); return;
}
#endif

client code:
   someFunction(arg);


The runtime cost would be negligible (if any), but it'd turn the code
into much less of a spaghetti.
What do you think?




Or slightly better:

.h file:
#if OPTIONAL_FEATURE
extern void someFunction();
#else
// #define someFunction() // NOP
// or:
// static inline someFunction() {/* NOP */}
#endif

.cc file:
#if OPTIONAL_FEATURE
void someFunction()
{
  //code
}
#endif

client code:
  someFunction(arg);


Amos

Reply via email to