Hi folks,
I'm experienced with C and C++ programming, but I can't figure out what I'm doing wrong here. I want to have multiple files in my project, the main file containing setup() and loop(), one other file with functions, one other with structures, etc...
When I put everything in the main file, it compiles just fine, which is not the cas with separate files. Here is my code :
final.ino
void setup()
{
initSensors();
}
void loop()
{
getDataSensors();
}
sensors.ino
void initSensors()
{
}
struct sensorData getDataSensors()
{
struct sensorData data;
data.gyroX = 200;
data.gyroY = 130;
data.gyroZ = -75;
data.accX = -500;
data.accY = 45;
data.accZ = 112;
return data;
}
structures.ino
typedef struct sensorData
{
int gyroX;
int gyroY;
int gyroZ;
int accX;
int accY;
int accZ;
};
The code actually does nothing, it's just for the purpose of testing. I'm using arduino software 1.0. The mistakes I get :
final.cpp: In function 'void loop()':
final:15: error: invalid use of incomplete type 'struct sensorData'
final:-1: error: forward declaration of 'struct sensorData'
final.cpp: In function 'sensorData getDataSensors()':
sensors:10: error: return type 'struct sensorData' is incomplete
sensors:10: error: new declaration 'void getDataSensors()'
final:-1: error: ambiguates old declaration 'sensorData getDataSensors()'
sensors:12: error: aggregate 'sensorData data' has incomplete type and cannot be defined
Am I missing something here ?
Also, one thing I've noticed, if I write a structure and use a typedef, the typedef doesn't seems to be taken in account. I've tried both syntax :
typedef struct foo foo;
struct foo
{
//...
};
typedef struct foo
{
//...
}foo;
None of the typedef works, I always have to write "struct foo" instead of "foo" if I want the program to compile.
Any help would be greatly appreciated