C on embedded systems has traditionally use structs to hold structured data.
Arduino brings C++ to the table, so we can use classes instead.
Lets say we have two different data structures which could be considered very similar:
typedef struct
{
int valueOne;
int valueTwo;
int valueThree;
} value_t;
and:
class Value
{
public:
int valueOne;
int valueTwo;
int valueThree;
}
In terms of memory, what difference will this make?
I still see the struct technique being used heavily - why is this?
struct
andclass
besides the default visibilitystruct
s are used primarily because the great majority of embedded hardware is coded in C, so anyone who spends a lot of time writing code for small MCUs probably knows C much better then C++, and automatically reaches for C idioms before C++ idioms. It's a programmer performance issue.