mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

 

 

 

 

Accessing Nested Structures

If structure B contains a field whose type is structure A, the members of A can be accessed by two applications of the member selectors:

struct A {

int j; double x;

};

struct B {

int i; struct A a; double d; } s, *sptr;

//...

s.i = 3; s.a.j = 2; sptr->d = 1.23; sptr->a.x = 3.14;

//assign 3 to the i member of B

//assign 2 to the j member of A

//assign 1.23 to the d member of B

//assign 3.14 to x member of A

page

78

Structure Uniqueness

Each structure declaration introduces a unique structure type, so that in

struct

A {

 

 

 

int

i,j;

double

d;

}

aa,

aaa;

 

 

struct

B {

 

 

 

int

i,j;

double

d;

}

bb;

 

 

 

the objects aa and aaa are both of type struct A, but the objects aa and bb are of different structure types. Structures can be assigned only if the source and destination have the same type:

aa= aaa; /* OK: same type, member by member assignment */

aa = bb; /* ILLEGAL: different types */

/* but you can assign member by member: */ aa.i = bb.i;

aa.j = bb.j; aa.d = bb.d;

MikroElektronika: Development tools - Books - Compilers