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
I tried it and the result is the same. Declaration and syntax error for both. It looks like there is something with compiler.
Could you please try the following:
typedef struct{
int x;
int y;
} new_struct;
new_struct my_new_struct:
void foo (void)
{
my_new_struct.x=0;
}
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;
}
Thank you. The problem was that I didnt create the variable of struct type. But there was also some minor problem because I declared it in header. Now its working well
Thanks for the feedback PGO.
Hopefully this will help Marek.