Why is it difficult to write portable C programs?

前端 未结 10 2638
野的像风
野的像风 2020-12-14 03:50

I want to know, why is it too hard to make a program run in many OSes, like Windows and Linux, without including glue code. They all share the same architecture (x86), so I

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 04:12

    The code is portable, but thats not the problem.

    The problem is that most larger applications use libraries which are part of the OS. So for example if you write a network app it might use the built in UPNP library for windows, and the Bonjour library on OS X, and some other zero-conf service on other unix flavors.

    Another example would could a simple notepad application. It might use the native save-file dialogues for the OS it is running on. A different version would need to be compiled for each OS to bind to the save-file dialogue library for that OS.

    I hope these examples are clear enough :)

提交回复
热议问题