Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I pass typedef or enum in Arduino?

The following sketch to fails to compile in the Arduino environment.

Given that typedefs can be used within Arduino software, is Automatic Prototype Generation the underlying mechanism that causes the failure? If so, what is it and why isn't Arduino providing a lightweight wrapper around 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() {}

For the benefit of the search engines, the errors reported are:

error: variable or field 'myFunc' declared void
error: 'MyMeaningfulType' was not declared in this scope
like image 461
Josh Avatar asked Aug 10 '13 02:08

Josh


1 Answers

Please refer to http://arduino.cc/en/Hacking/BuildProcess the specific quote is:

This means that if you want to use a custom type as a function argument, you should declare it within a separate header file.

This page does a good job of explaining how the Arduino Language is different from C/C++ in how it works/pre-processes files.

like image 113
JackCColeman Avatar answered Sep 27 '22 17:09

JackCColeman