以下草图无法在 Arduino 环境中编译。
鉴于typedefs can be used within Arduino software , Automatic Prototype Generation 是导致失败的底层机制吗?如果是,它是什么?为什么 Arduino 不提供围绕 C++ 的轻量级包装器?
#define PRODUCE_WACKY_COMPILETIME_ERROR
typedef int MyMeaningfulType;
#ifndef PRODUCE_WACKY_COMPILETIME_ERROR
void myFunc(MyMeaningfulType myParam);
#endif
void myFunc(MyMeaningfulType myParam)
{
myFunc(10);
}
void setup() {}
void loop() {}
为了搜索引擎的利益,报告的错误是:
error: variable or field 'myFunc' declared void
error: 'MyMeaningfulType' was not declared in this scope
最佳答案
请引用http://arduino.cc/en/Hacking/BuildProcess具体报价是:
This means that if you want to use a custom type as a function argument, you should declare it within a separate header file.
此页面很好地解释了 Arduino 语言在工作/预处理文件方面与 C/C++ 的不同之处。
关于c++ - 为什么我不能在 Arduino 中传递 typedef 或 enum?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18158136/