且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用 C 编写跨平台应用程序

更新时间:2023-10-16 23:34:28

我维护了一个 ANSI C 网络库多年,该库已移植到近 30 种不同的操作系统和编译器.该库没有任何 GUI 组件,这使它变得更容易.我们最终将任何跨平台不一致的例程抽象到专用源文件中,并在这些源文件中适当地使用#defines.这使每个平台调整的代码与库的主要业务逻辑隔离开来.我们还广泛使用了 typedef 和我们自己的专用类型,以便我们可以根据需要轻松地根据平台更改它们.这使得移植到 64 位平台变得相当容易.

I maintained for a number of years an ANSI C networking library that was ported to close to 30 different OS's and compilers. The library didn't have any GUI components, which made it easier. We ended up abstracting out into dedicated source files any routine that was not consistent across platforms, and used #defines where appropriate in those source files. This kept the code that was adjusted per platform isolated away from the main business logic of the library. We also made extensive use of typedefs and our own dedicated types so that we could easily change them per platform if needed. This made the port to 64-bit platforms fairly easy.

如果您正在寻找 GUI 组件,我建议您查看 GUI 工具包,例如 WxWindows 或 Qt(它们都是 C++ 库).

If you are looking to have GUI components, I would suggest looking at GUI toolkits such as WxWindows or Qt (which are both C++ libraries).