I am writing a Ruby C Extension where I use math.h
It compiles on both OSX and Windows. On Windows, I use nmake
, which comes with Visual Studio Express C ++ 2010.
I found that VS did not include the round()
function in my math.h
So I added this to compensate:
static inline double round( double value ) { return floor( value + 0.5 ); }
This course caused an error when compiling under OSX as round()
. (The actual error, I think, was declared by my statics after it was declared a non-static version.
Regardless, I would like to avoid overriding the function if it exists.
At the moment, I have this condition:
#ifdef _WIN32 static inline double round( double value ) { return floor( value + 0.5 ); } #endif
This worked in my scenario - but it seems a bit general. I mean, what if I compile with another compiler for Windows?
So my question is: can I determine if a function is defined, and then not define it myself?
Or, can I specifically define the nmake
use- cl
compiler nmake
I think it is?
I think that ideally I could determine if this function was already defined, since it seems to be the most reliable method.
source share