有没有理由使用C代替C ++进行嵌入式开发? [英] Is there any reason to use C instead of C++ for embedded development?

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

问题描述

问题



我的硬件上有两个编译器C ++和C89



我正在考虑使用C ++与类但没有多态(以避免vtables)。
我想使用C ++的主要原因是:




  • 我更喜欢使用内联函数而不是宏定义

  • 我想使用命名空间,因为我前缀混乱了代码。

  • 我看到C ++有点类型更安全,主要是因为模板,

  • 我真的很喜欢重载函数和构造函数(用于自动转换)。



在开发非常有限的硬件(4kb RAM)时,您是否有理由坚持使用C89?



结论



谢谢你的答案,他们真的很有帮助!



我以为这个主题,我会坚持使用C主要是因为:


  1. 在C中预测实际代码更容易,如果只有4kb的ram,这是非常重要的。

  2. 我的团队主要由C开发人员组成,所以高级的C ++功能不会被频繁使用。

  3. 我已经找到了一种内联函数在我的C编译器(C89)。

很难接受一个答案,因为你提供了很多好的答案。
不幸的是,我不能创建一个wiki并接受它,所以我会选择一个让我想起最多的答案。

解决方案

使用C超过C ++的两个原因:


  1. 对于很多嵌入式处理器,无论是没有C ++编译器,还是有我的经验是,嵌入式软件工程师中有重要的比例很少或没有C ++的经验 - 或者是因为(1),或者因为它不会被教授在电子工程学位上,所以最好坚持他们所知道的。

另外,原来的问题,和一些评论,提到RAM的4 Kb 。对于典型的嵌入式处理器,RAM的数量(大部分)与代码大小无关,代码存储并从闪存运行。



当然,代码存储空间的大小是需要牢记的,但是随着新的,更广泛的处理器出现在市场上,它不如以前是除了成本敏感的项目之外的所有问题。



关于使用C ++子集与嵌入式系统一起使用:现在有一个 MISRA C ++ 标准,这可能值得一看。



编辑:另见这个问题,这导致了C / C ++嵌入式系统的争论。


Question

I have two compilers on my hardware C++ and C89

I'm thinking about using C++ with classes but without polymorphism (to avoid vtables). The main reasons I’d like to use C++ are:

  • I prefer to use "inline" functions instead of macro definitions.
  • I’d like to use namespaces as I prefixes clutter the code.
  • I see C++ a bit type safer mainly because of templates, and verbose casting.
  • I really like overloaded functions and constructors (used for automatic casting).

Do you see any reason to stick with C89 when developing for very limited hardware (4kb of RAM)?

Conclusion

Thank you for your answers, they were really helpful!

I thought the subject through and I will stick with C mainly because:

  1. It is easier to predict actual code in C and this is really important if you have only 4kb of ram.
  2. My team consists mainly of C developers, so advanced C++ features won't be frequently used.
  3. I've found a way to inline functions in my C compiler (C89).

It is hard to accept one answer as you provided so many good answers. Unfortunately I can't create a wiki and accept it, so I will choose one answer that made me think most.

解决方案

Two reasons for using C over C++:

  1. For a lot of embedded processors, either there is no C++ compiler, or you have to pay extra for it.
  2. My experience is that a signficant proportion of embedded software engineers have little or no experience of C++ -- either because of (1), or because it tends not to be taught on electronic engineeering degrees -- and so it would be better to stick with what they know.

Also, the original question, and a number of comments, mention the 4 Kb of RAM. For a typical embedded processor, the amount of RAM is (mostly) unrelated to the code size, as the code is stored, and run from, flash.

Certainly, the amount of code storage space is something to bear in mind, but as new, more capacious, processors appear on the market, it's less of an issue than it used to be for all but the most cost-sensitive projects.

On the use of a subset of C++ for use with embedded systems: there is now a MISRA C++ standard, which may be worth a look.

EDIT: See also this question, which led to a debate about C vs C++ for embedded systems.

这篇关于有没有理由使用C代替C ++进行嵌入式开发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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