Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended way to organize platform specific code in C++? [closed]

If I want to write my C++ application for multiple platforms, e.g. Windows and Linux, what is the recommended way of writing the platform code? What pattern, class hierarchy etc. exists to accomplish this task? How should I organize my code, header and source files?

like image 449
tyrondis Avatar asked Oct 14 '12 21:10

tyrondis


1 Answers

I don't get your question completely, but generally you should separate your platform dependent code from platform independent one. for example you may have a folder platform and inside it a folder for each platform that supported by you, then you may have win32/mutex.hpp, linux/mutex.hpp, mac/mutex.hpp and in each of them you may add implementation of mutex for that platform. Then all you need is a single selector header that based on platform select correct file and include it. For example platform/mutex.hpp that include any of specified files in correct platform.

But beside that, take a look at boost it implement many platform dependent code in a platform independent manner, you can learn from it and you may see implementation of your platform dependent code there!!

like image 189
BigBoss Avatar answered Oct 07 '22 11:10

BigBoss