version: arduino-0012 (I think the bug is in 0011 as well)
There appears to be a bug with the preprocessing and the function prototyping. Some functions that are defined with pass by reference parameters are skipped and do not get prototype definitions in the resulting .cpp file.
For example, take this simple sketch:
byte a;
void setup()
{
}
void loop()
{
Function1(a);
Function2(a);
}
Then add a second tab (or add this code after the loop() function:
void Function1(byte var) {
// This function gets a prototype
}
void Function2(byte &var) {
// This function doesn't get a prototype
var=1;
}
Trying to compile this sketch will result in:
In function 'void loop()':
error: 'Function2' was not declared in this scope
This is because no prototype is generated for Function2, only for Function1. Here is the resulting .cpp file:
#include "WProgram.h"
void setup();
void loop();
void Function1(byte var);
byte a;
void setup()
{
}
void loop()
{
Function1(a);
Function2(a);
}
void Function1(byte var) {
// This function gets a prototype
}
void Function2(byte &var) {
// This function doesn't get a prototype
var=1;
}
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
The work-around is to manually add the missing prototype declarations before the functions are referenced. Overall it makes keeping your code organized in multiple tabs difficult since you don't (seem) to have any control of the order of the final assembled program. If the prototyping was working correctly then the order wouldn't matter.