typedef的工作不作为的Arduino草图功能参数或返回 [英] Typedef not working as parameter or return in Arduino sketch function
问题描述
我试着做了Arduino的IDE链表。
Im trying to do a linked list in the Arduino ide.
code是如下:
typedef struct ll{
struct ll * prev;
unsigned int currTime;
unsigned int stopTime;
struct ll * next;
} TIMING;
TIMING * head;
TIMING * current;
void setup();
void add_new_first(int stopTimer, TIMING * head);
void main() {
init();
setup();
// Code that uses the def
head->prev = NULL;
head->next = NULL;
head->currTime = 0;
head->stopTime = 200;
}
还有的职能末的实际code。
There is also the actual code of the functions at the end.
这个例子给我的错误:
service_timer_cpp.cpp:5:34:错误:时序尚未声明。
service_timer_cpp.cpp:5:34: error: ‘TIMING’ has not been declared.
在不使用定义的类型作为参数或者从它的工作原理没有错误的函数返回。
When not using the defined type as a parameter or return from a function it works without errors.
这是我怎么想它可以用C来完成,并已早先为我工作。我不明白为什么它没有在Arduino的环境中工作。
This is how I thought it could be done in c and has worked for me earlier. I don't understand why it is not working in the Arduino environment.
推荐答案
据的的我们的同胞Adruino开发商之一,preprocessor工作方式与正规C.有一些code代发生在编译过程中即时,这是中详细 http://arduino.cc/en/Hacking/BuildProcess 解释:
According to one of our fellow Adruino developers, the preprocessor works differently than for regular C. There's some code generation happening on-the-fly during the compilation, which is explained in detail in http://arduino.cc/en/Hacking/BuildProcess:
转换到主草图文件
Arduino的环境中执行一些转换到主
素描文件(草图中的所有选项卡,而不级联
它传递给AVR-gcc编译器之前,扩展)。首先,的#include
Arduino.h,或者为小于1.0版本,#包括WProgram.h是
添加到您的草图的顶部。这个头文件(在发现
/硬件/核心//)包括所需的所有defintions
为标准Arduino的核心。
The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler. First, #include "Arduino.h", or for versions less than 1.0, #include "WProgram.h" is added to the top of your sketch. This header file (found in /hardware/cores//) includes all the defintions needed for the standard Arduino core.
下一步,你的主要草图文件中的环境搜索功能定义和他们创造的声明(原型)。这些
任何意见或pre处理器语句(#包括后插入
#定义或),但在任何其他语句(包括类型
声明)。这意味着,如果你想使用自定义类型作为
函数的参数,你应该单独报头内声明它
。文件同时,这一代人是不完美:它不会产生
原型函数具有默认参数值,或
命名空间或类中声明。
Next, the environment searches for function definitions within your main sketch file and creates declarations (prototypes) for them. These are inserted after any comments or pre-processor statements (#includes or #defines), but before any other statements (including type declarations). This means that if you want to use a custom type as a function argument, you should declare it within a separate header file. Also, this generation isn't perfect: it won't create prototypes for functions that have default argument values, or which are declared within a namespace or class.
最后,目前的目标的main.cxx文件的内容是
添加到您的草图的底部。
Finally, the contents of the current target's main.cxx file are appended to the bottom of your sketch.
这就是为什么结构LL
工作正常作为一种类型(无typedef的需要),但typedef'ing导致编译错误,在code,你别看不到。
This is why struct ll
works fine as a type (no typedef needed), but typedef'ing leads to a compilation error in the code that you don't see.
这篇关于typedef的工作不作为的Arduino草图功能参数或返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!