跟进 this comment来自问题 Writing firmware: assembly or high level? :
为 Arduino 编译 C++ 代码时平台,可以使用虚函数、异常等吗?或者您想(必须)使用 C++ 的一个子集(如 the comment 中所述)?
为 Arduino 平台编程时还有其他注意事项吗?
最佳答案
Arduino 环境使用 GCC 工具链的 AVR 版本。代码编译为 C++,因此您可以使用类。虚拟功能是可能的; vtables 将存储在 .data 部分并具有正确的地址。事实上,Print 基类使用虚函数来使各种“打印”方法适应不同的输出类型。
由于代码空间原因,不支持异常。 Arduino 环境将“-fno-exceptions”传递给编译器命令行。见 the source进行验证。
支持模板。例如,this no-cost stream insertion operator technique使用简单的模板和内联运算符即可正常工作。
关于c++ - Arduino C++ 代码 : can you use virtual functions and exceptions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/461836/