C ++在小尺寸微控制器上 [英] C++ on Small-Footprint Microcontrollers

查看:97
本文介绍了C ++在小尺寸微控制器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,人们总是回避,或者强烈反对在微控制器上使用C ++,但我不能为我的生活弄清楚为什么。如果你远离大型C ++库(例如STL),并且不尝试使用复杂的功能,如RTTI或异常处理,C和C ++之间有没有明显的区别?虚拟继承对复杂性或足迹有很大的影响吗?我会认为这将是一个额外的内存,但大部分的复杂性将由编译器处理,但后来我不知道很多关于那个黑魔法。我只是不明白为什么人们相当坚持使用C,除了几个架构,有没有C ++编译器(如果有任何)。看起来模块化和模板的好处是一个没有脑子的,即使你不能使用你的cin或cout。

It seems to me people consistently shy away from, or rather vehemently oppose the use of, C++ on microcontrollers, but I can't for the life of me figure out why. If you stay away from large C++ libraries (e.g. STL) and you don't try to use complicated features like RTTI or exception handling, is there really any noticeable difference between C vs C++? Does virtual inheritance have a huge impact on complexity or footprint? I would think it'd be a little extra memory, but most of the complexity would be handled by the compiler, but then again I don't know a lot about that dark magic. I just don't understand why people are pretty adamant about using C, except maybe for the few architectures for which there aren't C++ compilers (if there are any). It seems the benefits of modularization and templates would be a no-brainer, even if you couldn't use your cin or cout.

我问,因为我做一些研究一些爱好项目我想工作。理想情况下,我想使用C ++严格的能力,以良好的模块化的东西,而C的SomeClass_SomeMethod(struct object * this ...)的方法面向对象。 (我更喜欢对象Pascal这些项目,但唉支持那种语言不是完全恒星...)我宁愿避免移动到一个更多能力的微处理器,因为A.对于我正在做的项目,我不需要大量的资源..我不打算编写60状态卡尔曼滤波器或编码1080p视频B.(真正的踢球)我想使用DIP和QFP包的处理器。

I ask because I'm doing some research for some hobby projects I'd like to work on. Ideally, I'd like to work with C++ strictly for the capability to nicely modularize things, vs. C's "SomeClass_SomeMethod( struct object* this ... )" approach to "object orientedness". (I'd much prefer object Pascal for these projects, but alas support for that language isn't exactly stellar...) I would rather avoid moving to a much more capable microprocessor because A. for the projects I'm doing, I don't need tons of resources.. I'm not planning on writing 60 state Kalman filters or encoding 1080p video B. (the real kicker) I'd like to use processors available in DIP and QFP packages. I'd like the ability to prototype without soldering or baking anything in my toaster oven.

任何想法?

推荐答案

在C ++中,你基本上只需要支付你使用超过或超过C语言编译代码,一些额外是免费的。

In C++ you essentially only pay for what you use over and above what would otherwise be C compilable code, and some of the extras are cost free.

一些C ++编译器对于小目标的最大问题是可用的C ++实现的完整性或C ++编译器的可用性。

The biggest issue with some C++ compilers for small targets is the completeness of available C++ implementations or the availability of a C++ compiler at all.

EETimes / Embedded.com多年来一直对这个主题发表一些文章:

EETimes/Embedded.com has run a number of articles on the subject over the years:

  • Better even at the lowest levels - Dan Saks
  • Embedded C++ Yields Faster Smaller Code - John Carbone
  • Why C++ is a viable alternative to C in embedded systems design - Fergus Bolger
  • Poor reasons for rejecting C++ - Dan Saks
  • Using C++ Efficiently in Embedded Applications - Mentor Graphics/Cesar A. Quiroz
  • The Inefficiency of C++ , Fact or Fiction? - IAR Systems/Anders Lundgren

这些文章最重要的一点是你不必使用所有的C ++在嵌入式系统中,他们测量或解释成本的内存,速度和各种功能的确定性。您使用的部分将取决于应用程序的性质(例如,它是否具有实时限制),以及您的目标平台的可用资源和性能。

The point most of these articles make is that you should not necessarily use all of C++ in an embedded system and they measure or explain the cost in terms of memory, speed, and determinism of various features. What parts you use will depend on the nature of your application (whether it has real-time constraints for example), and the available resources and performance of your target platform.

这篇关于C ++在小尺寸微控制器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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