c++ - 为什么我不能在 Arduino 中传递 typedef 或 enum?

标签 c++ arduino typedef

以下草图无法在 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/

相关文章:

python - Arduino Serial.readBytes 与 RPi 通信的奇怪行为

c++ - 打印字符串构建函数的输出未返回预期结果

C++ typedef 需要::type

c++ - 使用 makefile 构建时 GCC 不使用的预编译 header

c++ - 如何在 C++ 中读取/写入应用程序的内存

c++ - C++命令行软件

c - Arduino推特互动

头文件中的 C typedef 在文件范围内可变修改

c - 在 C 中获取 typedef 的名称?

c++ - 内存表大小