Reputation: 692
It is possible how I can determine OS and OS version in preprocessor?
I want to devide Solaris 10 and other OS's.
Upvotes: 1
Views: 192
Reputation: 2310
To expand on skoy's answer, for anyone looking to determine information the system on which the program is being compiled, there is a wiki page on a sourceforge project that has a list of most predefined macros for a couple of different things such as operating systems, architectures and compilers.
Upvotes: 0
Reputation: 276
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 _WIN32
macro 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.
Upvotes: 1