Helo Im tryng to implemente struct, but I got a error, so I created a test file.
struct tes{
char a;
char b;
};
typedef struct tes TES;
struct te{
char t;
static TES e;
//static struct TES s;
};
typedef struct te tte;
void setup(){
//memset( &Ste, 0x00, sizeof(struct te) );
//static struct te Ste;
}
void loop()
{
tte SSte;
if (SSte.e.a)
{
delay(10);
}
}
and I get the error:
test_struct.cpp.o: In function loop': C:\Users\*\Downloads\arduino-nightly/test_struct.ino:22: undefined reference to te::e'
system
May 17, 2014, 11:34pm
2
Try removing the static keyword from the struct definition.
You could also try this:
typedef struct {
char a;
char b;
} tes;
typedef struct {
char t;
tes e;
} tte;
void setup(){
}
void loop()
{
tte SSte = {0,{1,0}}; //Initialise the new variable - I think this may be a gcc extension?
if (SSte.e.a)
{
delay(10);
}
}
I don't think you can have a static element in a struct. It would defeat the purpose of being able to memset and memcpy the entire struct which is assumed to be contiguous bytes.
If you wanted to have a static shared component of part of the structs data, you could put the common data in a struct and then have an element of all of the other structs which is a pointer to that data.
#include <string.h>
#include <avr/io.h>
typedef struct {
char a;
char b;
} Ntes;
typedef struct {
char t;
Ntes e;
Ntes s;
} tte;
static tte Ste;
void setup(){
memset( &Ste, 0x00, sizeof(tte) );
}
int main(void) {
setup();
if (Ste.e.a)
{
PORTB = 0xFF;
}
}
some guy at avr freak answered this question.