Program portability

后端 未结 12 1268
栀梦
栀梦 2020-12-30 04:26

How to make sure that my program will be fully portable?

12条回答
  •  心在旅途
    2020-12-30 04:50

    It is impossible. What happens when I write my operating system that has a weird C compiler?

    That said, to be portable, you need to:

    • Avoid Win32
    • Avoid POSIX (which is annoying... You may want to just use Cygwin to provide Windows support)
    • Avoid any platform specific library. This usually limits you in graphics to wxWindows, GTK, and QT.
    • TEST. Make sure it works.
    • Don't assume anything. Windows is weird and uses \r\n, so be careful about that.
    • I think Visual C++ on windows gives you warnings about "unsafe c functions" and asks you to use the "safe ones", which are not standard. Don't fall for Microsoft's attempt to monopolize your program.

    Some things will help:

    • Autoconf will allow any decent system (ie one that includes a shell) to detect common portability issues and set up the correct headers
    • Cmake can do this as well, but only on platforms that Cmake itself is available on

提交回复
热议问题