Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Detecting Windows or Linux...

SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
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.
[code]
#ifdef WINDOWS
...
#endif

#ifdef LINUX
...
#endif
[/code]
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.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • LundinLundin Posts: 3,711Member
    The compiler switch for windows should be #ifdef _WIN32. I have no idea what the equal one for unix is.
  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    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.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
Sign In or Register to comment.