Like Arrch said, it would help if you posted the error. It probably has to do with how the IDE changes your code. If I compile your posted code, the IDE (version 1.0.1) changes it to the following.
In libraries (.cpp/.c and .h files), the Arduino library is not automatically included. The Arduino libary contains many useful functions to control Arduino, and make programming easier. In regular sketches,
#include "Arduino.h"
is automatically added at the top of the sketch before compilation begins.
I have question:
In standard c++, the datatype bool is used for true/false. Why did the Arduino library make boolean, which basically is the same thing?
dkl65:
When initialzing a struct named Command, you do not need to write "Command" after "struct"; only at the end before the semi-colon:
typedef struct
{
boolean Active;
char Color;
int Status;
int Duration;
} Command;
That creates an anonymous struct. spowers225, may not want to do that.
Notice the typedef? That's the C way of doing what c++ does. They generally only add names when it's a linked list and you need a pointer to it within itself.
dkl65:
When initialzing a struct named Command, you do not need to write "Command" after "struct"; only at the end before the semi-colon:
typedef struct
{
boolean Active;
char Color;
int Status;
int Duration;
} Command;
That creates an anonymous struct. spowers225, may not want to do that.
Notice the typedef? That's the C way of doing what c++ does. They generally only add names when it's a linked list and you need a pointer to it within itself.
I bow my head in shame. You are right.
From the C++98 Spec, Section 7.1.3.5
If the typedef declaration defines an unnamed class (or enum), the first typedef-name
declared by the declaration to be that class type (or enum type) is used to denote the
class type (or enum type) for linkage purposes only (3.5).
typedef struct { } *ps, S; // S is the class name for linkage purposes
This is the error I am receiving as a result of trying to compile an array of struct:
URL_Parser.c:21: error: expected '=', ',', ';', 'asm' or 'attribute' before 'Commands'
URL_Parser.c:30: error: expected '=', ',', ';', 'asm' or 'attribute' before '*' token
URL_Parser.c: In function 'sendCharacter':
URL_Parser.c:46: error: 'Commands' undeclared (first use in this function)
URL_Parser.c:46: error: (Each undeclared identifier is reported only once
URL_Parser.c:46: error: for each function it appears in.)
I am declaring the array this way:
Command Commands[3]; //red = 0, green = 1, yellow = 2
And my Command.h file contains the struct: #ifndef COMMAND_H #define COMMAND_H
#include "Arduino.h"
struct Command
{
boolean Active;
char Color;
int Status;
int Duration;
};
You can either turn Command into a typedef or you can use the C++ compiler instead of the C compiler. I suggest the latter. Simply rename URL_Parser.c to URL_Parser.cpp and resolve any problems that arise.