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;
// assign 3 to the i member of B
s.a.j = 2;
// assign 2 to the j member of A
sptr->d = 1.23;
// assign 1.23 to the d member of B
sptr->a.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 type struct A, but the objects aa and bb are of
different structure types. Structures can be assigned only if the source and destina-
tion 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;
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
78
MikroElektronika:
Development
tools
-
Books
-
Compilers
page