1

I'm currently writing a set of modules with parameters that can be defined at compile time. For each value, I'm also specifying a default value, so that a user only needs to define those values they want to change. There is a user-defined include file, which contains the #define macros with the overwritten values.

In my module, I'm using

#include "user-defines.h"
#include "module.h"

where module.h contains the default definitions.

Currently, I'm using the following pattern for defining the default values in module.h

#ifndef somemacro
#define somemacro "default value"
#endif

which works, but means a lot of extra typing. It is also three lines instead of one, blowing up the source code.

My question is, is there a more elegant way (e.g. 1 line, not repeating the macro name) to define the default value only in case it is undefined?

Peter B.
  • 371
  • 2
  • 16

0 Answers0