Writing portable code Linux/Windows

One: never name a anything as ‘small‘. Why? This is defined under RpcNdr.h header file:
#define small char;

Two: never name a anything as ‘FindText‘. Why? This is defined under CommDlg.h header file:
#ifdef UNICODE
#define FindText FindTextW
#else
#define FindText FindTextA
#endif // !UNICODE

Three: if you use ‘__PRETTY_FUNCTION__‘ with GCC prepare that is not part of C++ standard! But you can use the following define:
#ifdef _MSC_VER
#define __PRETTY_FUNCTION__ __FUNCSIG__
#endif

http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.80%29.aspx

Four: Visual Studio does not like the use of ‘log10()‘ math function passing an int without explicitly casting it:
int foo;
int bar = 100;
foo = log10(bar);

needs to be something like:
int foo;
int bar = 100;
foo = log10((float)bar);

Five: again Visual Studio does not like the use of another math function like ‘pow()‘ passing (double, uint) without explicitly casting it:
double foo(10.0);
uint bar(2);
pow(foo, bar);

needs to be:
double foo(10.0);
uint bar(2);
pow(foo, (int)bar);

I hope this helped someone, do you have more? Drop a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *