开发者

portable code between windows and linux

I have an aplication written for lin开发者_StackOverflow社区ux,and i want to make it to execute under windows too. So how can i make a specific line in code to execute only if the programs runs under windows ? I know its somehting with #ifdef... Thanks


You're looking for:

#if defined(_WIN32)
    // Your Windows specific code here
#endif

Edit based on comment:

There is a good discussion of _WIN32 vs WIN32 here: Whats the difference between the win32 defines


It depends on the code. You might be able to just re-compile it and go. If not, the effort involved in porting may be trivial (a few minor details here or there) or it might be next to impossible (e.g., trying to port valgrind).

Before you jump into using #ifdef, read Henry Spencer's paper on the subject.


I use #ifdef _MSC_VER to know if it's a Microsoft compiler, but I'm sure there are other ways.


Usually #ifdef _WIN32, but #ifdef WIN32 also works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜