How to write portable code in c++?

后端 未结 12 1999
情话喂你
情话喂你 2020-11-30 03:47

What are the things that I should keep in mind to write portable code? Since I\'m a c++ beginner, I want to practice it since beginning.

Thanks.

12条回答
  •  隐瞒了意图╮
    2020-11-30 04:35

    Others said it before, but here is my view on it:

    1) Do you need C++? It's not the best language for writing portable code because it's close to the bare metal. Java, Python, Perl, PHP or Javascript might be better for you.

    2) If you need C++, don't try to write completely portable code, it's almost impossible anyway. Instead, decide early which platforms you want to support. For example: Linux, MacOS X, Windows

    3) Make sure you test your code on all selected platforms continously. Don't just build on Windows and expect to just compile a Linux version 'when it's done'. Compile on all platforms daily and make sure you keep testing them for problems.

提交回复
热议问题