Preprocessor check if multiple defines are not defined

Toby picture Toby · Jun 21, 2013 · Viewed 102.7k times · Source

I have a selection of #defines in a header that are user editable and so I subsequently wish to check that the defines exist in case a user deletes them altogether, e.g.

#if defined MANUF && defined SERIAL && defined MODEL
    // All defined OK so do nothing
#else
    #error "User is stoopid!"
#endif

This works perfectly OK, I am wondering however if there is a better way to check if multiple defines are NOT in place... i.e. something like:

#ifn defined MANUF || defined SERIAL ||.... // note the n in #ifn

or maybe

#if !defined MANUF || !defined SERIAL ||....

to remove the need for the empty #if section.

Answer

Sergey L. picture Sergey L. · Jun 21, 2013
#if !defined(MANUF) || !defined(SERIAL) || !defined(MODEL)