Detecting Windows or Linux...

SephirothSephiroth Fayetteville, NC, USA
I'm beginning to make my Windowing library work in Linux as well as Windows via the X library, but I have hit a small snag that I believe I know the answer to, but need confirmation on. I declare my own types in a header file which are defined as a plain Windows or X type based on which OS is detected so that users may write code with my types and then have the code compile on both platforms with no changes beyond "main()" and "WinMain()". My problem is figuring out what is defined in Windows as opposed to Linux to setup my types properly.
#ifdef WINDOWS

#ifdef LINUX
Are those the correct definitions to look for, or am I off base here? I've not really worked on a project that compiles on both platforms before and as such have never had the need to figure out what OS I am compiling on. It was always "this program is Windows only" or "this server application is Linux only". Now it's time to bridge the gap and it's been fun thus far! Thanks for the help.



  • The compiler switch for windows should be #ifdef _WIN32. I have no idea what the equal one for unix is.
  • SephirothSephiroth Fayetteville, NC, USA
    That's fine for testing against 32bit Windows, but my library works in 64bit Windows also. I need the definition that says "hey, you're in any version of Windows". Without that I have to add a third section for using 64bit Windows.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!