Preprocessor check if multiple defines are not defined
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.
#if !defined(MANUF) || !defined(SERIAL) || !defined(MODEL)
FWIW, @SergeyL's answer is great, but here is a slight variant for testing. Note the change in logical or to logical and.
main.c has a main wrapper like this:
#if !defined(TEST_SPI) && !defined(TEST_SERIAL) && !defined(TEST_USB)
int main(int argc, char *argv[]) {
// the true main() routine.
}
spi.c, serial.c and usb.c have main wrappers for their respective test code like this:
#ifdef TEST_USB
int main(int argc, char *argv[]) {
// the main() routine for testing the usb code.
}
config.h Which is included by all the c files has an entry like this:
// Uncomment below to test the serial
//#define TEST_SERIAL
// Uncomment below to test the spi code
//#define TEST_SPI
// Uncomment below to test the usb code
#define TEST_USB