It is possible how I can determine OS and OS version in preprocessor?
I want to devide Solaris 10 and other OS’s.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Like Jan Dvorak said, this depends on whether you’re referring to the host system (the one you’re compiling on) or the target system (the one your application will run on).
If the latter, there is no way to do what you want for the simple reason that this information is only available at runtime on the target system, while the preprocessor runs during compilation only.
If the former, your compiler should make available pre-defined MACROS that will give you some information about the system you’re compiling on. For example, when compiling using MingW or MSVC on Windows the
_WIN32macro will be defined to allow you to conditionally include code.However, this is unlikely to give you the information you seek because the OS version is usually irrelevant during compilation – the information you want is which OS you are compiling on (e.g.: Windows, Solaris), which compiler version, etc.