I have several drivers using a resource in my code, of which only one can be defined. eg if I have the following defines: USB_HID, USB_SERIAL, USB_STORAGE. and I want to test that only one is defined, is there a simple way to do this? Currently I am doing it this way:
#ifdef USB_HID
#ifdef USB_INUSE
#error "Can only have one USB device"
#else
#define USB_INUSE
#endif
#endif
#ifdef USB_SERIAL
#ifdef USB_INUSE
#error "Can only have one USB device"
#else
#define USB_INUSE
#endif
#endif
... with one of these blocks for each USB_XXX driver. Is there more elegant way of doing this?
#if defined(USB_HID) + defined(USB_SERIAL) + defined(USB_STORAGE) != 1
#error Define exactly one of USB_HID, USB_SERIAL, USB_STORAGE
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With