Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
mikroC PRO for PIC32
MikroElektronika
215
Accessing Nested Structures
If the structure 
B
 contains a field whose type is the structure 
A
, the members of 
can be accessed by two applications 
of the member selectors:
struct A {
  int j; double x;
};
struct B {
  int i; struct A aa; double d;
} s, *sptr;
...
s.i = 3;            // assign 3 to the i member of B
s.aa.j = 2;         // assign 2 to the j member of A
sptr->d = 1.23;     // assign 1.23 to the d member of B
sptr->aa.x = 3.14;  // assign 3.14 to x member of A
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  the  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;