More on typedef


1, C language two types: built-in types and user-defined types
(1) built-in types: ADT, custom types: the UDT
2, typedef definition (or called rename) instead of the type of variable
(1) Type is a data template, is a real variable data. Type of memory is not accounted for, and the variable is accounted for memory.
(2) object-oriented languages: the class type is a class, the object is variable.
3, typedef and #define distinction
typedef char * PCHAR;
#define PCHAR char *
. 4, the structure of the method defined
first: Student struct
  {
   char name [20 is];
   int Age;
  };
 for use when:
     struct Student S1 ; // struct student is type; S1 is variable
  s1.age = 20;
second: Student struct
  {
   char name [20 is];
   int Age;
  } student_t;
 when used:
     student_t S1;
  s1.age = 20;
 or definition of the structure is a pointer:
     struct Student * of pS1; // pointer to structure
  student_t * pS1; // structure pointer
third: Student typedef struct
  {
   char name [20 is];
   int Age;
  } Student, * pStudent;
 a definition of two types:
  a first type of structure is: There are two name: struct student, student;
  second structure is a pointer type: two names: struct Student *, pStudent;
. 5, the typedef structure
(1) is to define the structure type of structure in use, and then to define the structure for a variable type.
(2) C language syntax states: the structure must be of type struct structure type variable name structure name; in such a way to define variables.
(3) using typedef defined once two types, namely the type of structure variables, pointer type and structure variables.
6, typedef and const
(. 1) typedef int * PINT; p2 PINT const; equivalent int * const p2; // * p2 can be modified, but not change p2
(2) typedef int * PINT; PINT const p2; rather const * P2 to int;
(. 3) If you want a const int * p; this effect, only const int * CPINT typedef; CPINT P1;
. 7, using typedef meanings
(1) to simplify the type described
* char (*) (char *, char *); typedef char * (* pFunc) (char *, char *);
(2) In many programming system, people tend not to use int, double, etc. C language built-in type because these types are associated with the platform itself and (int type such as
when the machine type on a 16-bit 16-bit, 32-bit machine is in the 32-bit). To solve this problem, many programs use a custom type intermediate buffer to do.
For example Linux kernel used in this technique, to define the kernel: typedef int size_t; then required under a particular encoding size_t instead int.
(3) STM32 library using all type definitions, such as typedef volatile unsigned int vu32;  
 

Guess you like

Origin www.cnblogs.com/jiangtongxue/p/11387850.html