何时使用C代替C ++? [英] When to use C instead of C++?

查看:106
本文介绍了何时使用C代替C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下C是最佳选择?甚至比C ++还好?
请给出一些原因.

What are the situations where C is the best choice? even better than C++?
Please give some reasons

推荐答案

首先,C ++完全完全支持C.因此,如果要使用C,只需在C ++中进行即可.不会有任何区别.
如果您不在乎,请编写C ++.使用OOP时,性能会有所不同,但您实际上不必携带. C ++ OOP是最快的OOP.进行C OOP不会更快.无论如何,C ++并不强制您进行OOP.
使用C ++异常对于堆栈而言更昂贵.但是,如果您在乎,请不要使用C ++异常.
C ++模板,实际上对性能没有影响.
在某些特定情况下使用C语言.主要用于制作其他语言或程序的API,插件.在这种情况下,C充当了某些黑盒与通常的C ++或某些其他语言之间的桥梁.而且在某些特定于平台的环境中可能还需要C.但这并不总是意味着您受制于C.
First of all C++ quite fully supports C. So, if you want to use C, just do it in C++. There will be no difference.
If you don''t care, then write C++. Some difference in performance appears when using OOP, but you really don''t have to carry. The C++ OOP is the fastest OOP. Doing C OOP will not be faster. Anyway, C++ does not obligate you to do OOP.
Using C++ exceptions is more expensive for stack. But if you care, don''t use C++ exception.
C++ templates, really no impact on performance.
C language is used in some specific situations. Mostly for making API to other languages or programs, plugins. In this case C acts as a bridge between some blackbox and usually C++, or some other language. And also C can be required in some platform specific. But this does not always mean that you are constrained to C.


微控制器和DSP芯片仍经常使用C.许多进行内核级编程的人似乎也倾向于指向C [ ^ ].不过总的来说,我会说支持OOP的东西一起使用,因为将来它比纯C语言更易于维护和升级.对于大多数应用程序,两者之间的性能差异很小.
Microcontrollers and DSP chips still commonly use C. A lot of people that do kernel level programming also seem to lean towards C[^] as well. In general though, I''d say go with something that supports OOP, since it''s easier to maintain and upgrade in the future than pure C. The performance differences are minimal between the two for most applications.


对微型控制器进行编程时.即使如此,它仍然取决于您要为其编程的系统:

a)可能没有适用于micorcontroller的C ++编译器
b)由于占用空间较大,因此系统内存可能太受限制而无法使用C ++
c)负责人不知道现有的合适的C ++编译器

(a)变得越来越没有问题了,因为大多数提供C编译器的公司都试图提供C/C ++以保持竞争力
(b)的问题变得越来越少,因为与大的存储芯片相比,小的存储芯片制造成本更高(主要是由于需求低).
(c)由于此类网站而引起的问题越来越少,而像您这样的人也提出了这样的问题;-)
When programming microcontroolers. Even then it depends on the system you''re programming for:

a) there may be no C++ compiler for the micorcontroller available
b) your system memory may be too restricted to allow for C++ due to its larger footprint
c) the responsible person(s) is/are not aware of an existing, suitable C++ compiler

(a) is becoming less of a problem since most companies that provide C compilers try to provide C/C++ in order to remain competitive
(b) is becoming less of a problem since small memory chips become more expensive to manufacture than larger ones (mostly due to low demand).
(c) is becoming less of a problem due to sites like these, and people like you asking such questions ;-)


这篇关于何时使用C代替C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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