如何编写可移植的C/C ++程序? [英] How to write portable C/C++ program?

查看:133
本文介绍了如何编写可移植的C/C ++程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.能否给我一些建议/有用的链接/书
2,你能告诉我一些成功的可移植C/C ++项目吗?
3.您对编写可移植的GUI程序有任何想法吗?除了Java,QT是最好的选择?

解决方案

首先,没有C/C ++程序这样的东西. C和C ++是非常不同的语言,具有不同的习惯用法.

现在,如果您想使用任何一种语言进行便携式编程,那么周六早上我都会感到厌烦,那么K&R是C语言的不错参考,而Stroustrup的书(《 C ++编程语言》第3版)则是不错的选择. C ++参考.可移植编程要记住的一点是,如果在核心语言中存在一种实现方法,则永远不要使用OS功能或语言的供应商扩展.

有趣的便携式开源项目包括:

-OpenSSL
-外国人
-升压
-Python

如果要用C ++编写可移植的GUI,则有很多选项.我已经成功使用了FLTK和wxWidgets.但是,像RealBASIC这样的东西对我来说也很好用,因此将自己限制为C ++可能会出错.

干杯,

Ash


希望您能参考源代码的可移植性.这就是语言标准规范所擅长的,并且有很多(尽管很乏味)的方法来实现这一目标.请注意,您可能从JVE或.Net得知c ++(或c)程序没有二进制兼容性,这意味着为一个平台编译的代码无法在其他平台上运行.

1.Could you give me some suggestions/useful links/books
2.Could you tell me some successful portable C/C++ project that''s open source
3.Do you have any idea on writing portable GUI program? QT is the best choice except Java?

解决方案

First thing is there''s no such thing as a C/C++ program. C and C++ are very different languages with very different idioms.

Now I''ve got my saturday morning rant out of the way if you want to program portably in either language then K&R is a good reference for C and Stroustrup''s book ("The C++ Programming Language" 3rd edition) is a good reference for C++. The thing to remember with portable programming is never use an OS facility or vendor extension to a language when there''s a way of doing it within the core language.

Interesting portable open source projects include:

- OpenSSL
- Expat
- Boost
- Python

If you want to write portable GUIs in C++ then there are loads of options. I''ve used FLTK and wxWidgets successfully. However something like RealBASIC works pretty well for me as well so limiting yourself to C++ might be a bit of a mistake.

Cheers,

Ash


I hope you refer to source code portability. That''s what the language standard specification is good for and there are many (although tedious) ways to accomplish this. Please consider that there is no binary compatibility of c++ (or c) programs as you might know it from JVE or .Net meaning that a code compiled for one platform cannot be run on others.


这篇关于如何编写可移植的C/C ++程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆