View Single Post
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: how to identify which OS I am using

 
0
  #20
Oct 3rd, 2008
I think Duodas have posted a good example of multilevel environment recognition with subsequent macros standartisation (#define __WIN32__, for example). More complicated example from the Boost library:
http://www.boost.org/doc/libs/1_36_0...orm_config.hpp

The key point is: don't dissipate OS/compiler dependencies over all your codes. Incapsulate all this stuff in the only .h header file. Declare your own portable functions (and data structures) in this file. For example, suppose its name is omgconio.h:
  1. #ifndef OMGCONIO_H
  2. #define OMGCONIO_H
  3. ...
  4. /** Explain ClrScr functionality */
  5. void ClrScr();
  6. int Peek();
  7. bool KbHit();
  8. int GetCh();
  9. ...
  10. #endif
Use only these functions calls in your source(s).

Create omgconio.cpp file with these functions inplementation. Place all OS/compiler selecting conditional compilation directives in this file only. Add omgconio.h and omgconio.cpp files to your projects.

Now you know where is OS/compiler dependency incapsulated if you will be ready to expand or correct your platform independent direct console i/o support.
Reply With Quote