I have the following code:
#ifndef min
#define min(a,b) (((a)< (b)) ? (a) : (b))
#endif
int test(){
return min(0,1);
}
Which works OK. However, if I include some header file (from a graph database, the content of this header file can be found here: http://www.sparsity-technologies.com/dex), the compiler complains that min is not defined, like Dex.h just cancelled the effect of my marco definition.
However, Dex.h doesn't contain any undefined statements. I couldn't move the macro definition, because it is actually included in another header file.
What's wrong and what should I do?
#ifndef min
#define min(a,b) (((a)< (b)) ? (a) : (b))
#endif
#include "gdb/Dex.h"
int test(){
return min(0,1);
}
The compiler error I get is:
test.c:9:16: error: 'min' was not declared in this scope
std::maxandstd::min. No need to make a macro with a conflicting name. - chrisstd::min, tries to name a variablemin, or uses yourminmacro not expecting it to evaluate its arguments multiple times. (Conversely, things that aren't macros shouldn't be named in all uppercase, although many people have unfortunately perverted that to include non-macro constants.) - jamesdlin