Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
212
mikoC PRO for PIC32
MikroElektronika
Untagged Structures and Typedefs
If the structure tag is omitted, an untagged structure is created. The untagged structures can be used to declare the 
identifiers in the comma-delimited 
member-declarator-list
 to be of the given structure type (or derived from it), 
but additional objects of this type cannot be declared elsewhere.
It is possible to create a typedef while declaring a structure, with or without tag:
/* With tag: */
typedef struct mystruct { ... } Mystruct;
Mystruct s, *ps, arrs[10];  /* same as struct mystruct s, etc. */
/* Without tag: */
typedef struct { ... } Mystruct;
Mystruct s, *ps, arrs[10];
Usually, there is no need to use both 
tag
 and 
typedef
: either can be used in structure type declarations.
Untagged structure and union members are ignored during initialization.
Anonymous Structures
mikroC PRO for PIC32 allows you to declare a structure variable within another structure without giving it a name. 
These nested structures are called 
anonymous structures
.
You can access the members of an anonymous structure as if they were members in the containing structure:
struct phone{
  int  areacode;
  long number;
};
struct person {
  char   name[30];
  char   gender;
  int    age;
  int    weight;
  struct phone;    // Anonymous structure; no name needed
} Jim;
  Jim.number = 1234567; 
}
Related topics: Working with structures