|
发表于 2011-2-8 15:30:39
|
显示全部楼层
以下来自CVAVR的HELP
Defining Data Types Previous Top Next
--------------------------------------------------------------------------------
User defined data types are declared using the typedef reserved keyword.
The syntax is:
typedef <type definition> <identifier>;
The symbol name <identifier> is assigned to <type definition>.
Examples:
/* type definitions */
typedef unsigned char byte;
typedef struct {
int a;
char b[5];
} struct_type;
/* variable declarations */
byte alfa;
/* structure stored in RAM */
struct_type struct1;
/* structure stored in FLASH */
flash struct_type struct2;
/* structure stored in EEPROM */
eeprom struct_type struct3;
======================================================================================
Structures can be grouped in arrays.
Example how to initialize and access an global structure array stored in EEPROM:
/* Global structure array located in EEPROM */
eeprom struct eeprom_structure {
char a;
int b;
char c[15];
} se[2]={{'a',25,"Hello"},
{'b',50,"world"}};
void main(void) {
char k1,k2,k3,k4;
int i1, i2;
/* define a pointer to the structure */
struct eeprom_structure eeprom *ep;
/* direct access to structure members */
k1=se[0].a;
i1=se[0].b;
k2=se[0].c[2];
k3=se[1].a;
i2=se[1].b;
k4=se[1].c[2];
/* same access to structure members using a pointer */
ep=&se; /* initialize the pointer with the structure address */
k1=ep->a;
i1=ep->b;
k2=ep->c[2];
++ep; /* increment the pointer */
k3=ep->a;
i2=ep->b;
k4=ep->c[2];
} |
|