I am currently using three servers (deploy, live_testing, and local). I am using macros to define a serie of domain locations:
#define __LIVE_TESTING // Here I chose what domain to use
#ifdef __PRODUCTION
#define DOMAIN @"http://192.168.10.228/rest/"
#define DOMAINCOMET @"http://192.168.10.228/"
#endif
#ifdef __LIVE_TESTING
#define DOMAIN @"http://192.168.10.229/rest/"
#define DOMAINCOMET @"http://192.168.10.229/"
#endif
...
The issue I am having are compiler issues relating to the redefinition of DOMAIN and DOMAINCOMET. Is there a workaround for these warnings?
Thanks in advance, Clinton
#undef
is your friend:
#ifdef __LIVE_TESTING
#if defined(DOMAIN) && defined(DOMAINCOMET)
#undef DOMAIN
#undef DOMAINCOMET
#endif
#define DOMAIN @"http://192.168.10.229/rest/"
#define DOMAINCOMET @"http://192.168.10.229/"
#endif
If you are getting redefinition errors, you must be defining the macro more than once. If this code is the only place that DOMAIN
and DOMAINCOMET
are defined, then it is possible that your both control flags are set.
This could happen if both __PRODUCTION
and __LIVE_TESTING
are defined to any value - even 0 since you are using #ifdef
to see if they are defined, and not testing the actual value they are assigned.
For example, even:
#define __PRODUCTION 0
#define __LIVE_TESTING 1
will cause both blocks to be evaluated according to your code, and thus trigger the redefinition error.
If you want the two to be mutually exclusive, you should check their value, thus:
#if __PRODUCTION==1
#define DOMAIN @"http://192.168.10.228/rest/"
#define DOMAINCOMET @"http://192.168.10.228/"
#elif __LIVE_TESTING==1
#define DOMAIN @"http://192.168.10.229/rest/"
#define DOMAINCOMET @"http://192.168.10.229/"
#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