Structure

  1. Structure names form a separate namespace
    struct STRUCT {
      member1type member1;
      member2type member2;
    };
    
    usage in declarations and definitions requires keyword struct in C (recommended to C++ too)
    struct STRUCT s;
    
  2. typedef can be used to shorten declarations and definitions
    typedef struct STRUCT Struct;
    Struct s;
    
  3. typedef and struct declarations can be combined into one construct
    typedef struct STRUCT {
      member1type member1;
      member2type member2;
    } Struct;
    
  4. Typically, inner struct declaration needs no name
    typedef struct {
      member1type member1;
      member2type member2;
    } Struct;
    

Definition of pointer to structure type

typedef struct STRUCT {
  member1type member1;
  member2type member2;
} *Struct;

// usage in application
Struct s;	// variable of pointer type, not structure type
Pointer to structure is efficient in passing parameters, but definition of pointer to structure type leads many confusion and require manual memory allocation. With the introduction of reference variable, its usage is less popular.


Struct s[STRUCTNUM];
Struct *p = s;
p++;	// point to (s+sizeof s) = s[1]
Index