C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Detecting Windows or Linux... Posted by Sephiroth on 5 Apr 2009 at 1:47 PM
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
...
#endif

#ifdef LINUX
...
#endif

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.

-Sephiroth
Report
Re: Detecting Windows or Linux... Posted by Lundin on 6 Apr 2009 at 1:03 AM
The compiler switch for windows should be #ifdef _WIN32. I have no idea what the equal one for unix is.
Report
Re: Detecting Windows or Linux... Posted by Sephiroth on 6 Apr 2009 at 6:54 PM
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.

-Sephiroth



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.