Arduino C++ 代码:你能使用虚函数和异常吗? [英] Arduino C++ code: can you use virtual functions and exceptions?

查看:33
本文介绍了Arduino C++ 代码:你能使用虚函数和异常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟进此评论来自问题写固件:汇编还是高级?:

在为 Arduino 平台编译 C++ 代码时,是否可以使用虚函数、异常等?或者您想(必须)使用 C++ 的子集(如 中所述)评论)?

When compiling C++ code for the Arduino platform, can you use virtual functions, exceptions, etc? Or would you want to (have to) use a subset of C++ (as described in the comment)?

在为 Arduino 平台编程时还有其他注意事项吗?

Any other caveats when programming for the Arduino platform?

推荐答案

Arduino 环境使用 GCC 工具链的 AVR 版本.代码编译为 C++,因此您可以使用类.虚拟功能是可能的;vtables 将存储在 .data 部分并具有正确的地址.实际上,Print 基类使用虚函数使各种打印"方法适应不同的输出类型.

The Arduino environment uses the AVR version of the GCC toolchain. The code is compiled as C++, so you can use classes. Virtual functions are possible; the vtables will be stored in the .data section and have the correct addresses. In fact, the Print base class uses virtual functions to adapt the various "print" methods to the different output types.

由于代码空间原因,不支持异常.Arduino 环境将-fno-exceptions"传递给编译器命令行.请参阅来源以对此进行验证.

Exceptions are not supported because of code space reasons. The Arduino environment passes "-fno-exceptions" to the compiler command line. See the source for verification of this.

支持模板.例如,这种免费的流插入运算符技术使用简单的模板和内联运算符就可以很好地工作.

Templates are supported. For example, this no-cost stream insertion operator technique works fine using a simple template and inline operator.

这篇关于Arduino C++ 代码:你能使用虚函数和异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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