is there any c or c++ functions that will tell what OS is being used?
is there any c or c++ functions that will tell what OS is being used?
Ubuntu Desktop
GCC/G++
Geany (for quick projects)
Anjuta (for larger things)
There is no standard way to do that in a program.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
No because that information is OS dependent.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
The only standard function you can use is system(). You'd pass it a command line string such as "uname" on UNIX to display the OS, but of course if you don't know what OS you're on you probably won't know what command to pass to system().
Does it really matter though? If you try to run a UNIX program on Windows or visa versa, they certainly won't run.
True enough, you can't cross-run things anyways.
What you can do is to set a #define OS linux or #define OS windows (with -D in the compile flags for example).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I guess not. I was only wondering because there are display differences between a Linux terminal and the Windows command prompt, and thought it would be nice if I could compensate for those differences (thus necessitating the OS info). Oh well, if it was that important, I suppose I could ask the user...
Ubuntu Desktop
GCC/G++
Geany (for quick projects)
Anjuta (for larger things)
Well, the thing is, that if you want to USE any OS-specific features in your code, you need to know which OS you are building the application for. You can write a piece of code that tries a number of different options, but it would make very little sense, because it would have to be compiled for the OS it runs on, and at the point of building, you (as in the programmer and/or the makefile, project definition file or whatever) will know what OS this is for. So there's no point in making things more complicated by trying to do it at runtime.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.