Hello,
I am using eclipse based codewarrior for mcu 10.1 and I cant use structures, what Iam doing wrong?
struct steering {
int P;
};
steering left;
left.P=0;
typedef struct{
int x;
int y;
} new_struct;
new_struct.x=0;
In both examples I am getting declaration syntax error. It can make a structure but if I want to change its member I am getting declaration syntax error.
Thank You
已解决! 转到解答。
Hi Carlos,
Apart from the colon instead of a semi-colon, this compiles fine for me with CW10.1.
For reference - entire main.c:
#include <stdio.h>
#include "derivative.h" /* include peripheral declarations */
typedef struct {
int x;
int y;
} new_struct;
new_struct my_new_struct;
void main (void) {
my_new_struct.x=0;
}
Hi,
There are a couple of obvious problems.
You may be used to C++ which has some different rules to C.
Try:
struct steering {
int P;
};
struct steering left;
left.P=0;
You need to repeat the keyword struct
in the declaration of the variable.
typedef struct
int x;
int yl
}new_struct;
new_struct.x = 0;
This is illegal for two reasons:
typedef struct does not create a variable but a type instead.
You also cannot have declarations after executable statements e.g.
int x;
x = 4;
int y; /* Illegal */
bye
Hi Carlos,
Apart from the colon instead of a semi-colon, this compiles fine for me with CW10.1.
For reference - entire main.c:
#include <stdio.h>
#include "derivative.h" /* include peripheral declarations */
typedef struct {
int x;
int y;
} new_struct;
new_struct my_new_struct;
void main (void) {
my_new_struct.x=0;
}