Different from the type of TypeDef data

zhaozj2021-02-16  63

Different from the type of TypeDef data

DaizH

For the sake of brevity and writing, we usually use or alias for the type of data, usually there are two ways to implement, ie define macros, and typedef.

For example: #define STU STRUCT STU can use STU variable in the program Description: STU Body [5], * P;

#define Integer Int You can use Integer to make an integer variable in the program: Integer A, B;

Note that the macro definition indicates the difference between the data type and defines the data specifier with typedef. Macro definition is just a simple character string replacement, which is done in preprocessing, and TypeDef is processed at compile, it is not a simple substitution, but rename the type specifier. The named identifier has the function of type definition description. Please see the example below:

#define Pin1 Int *

TypedEf (int *) PIN2;

From the form of it, the two are similar, but it is not the same in actual use. When the variable is used in PIN1, PIN2 can be seen when the variables can be seen: PIN1 A, B; turn into int * a, b after macro generation; representing A means a pointer variable to the integer, and B is integer variable . : PIN2 A, B; represents A, B are all pointer variables to integer. Because Pin2 is a type of specifier. As can be seen from this example, although the macro definition can also represent the data type, it is made by the character. Be careful in use to avoid errors.

转载请注明原文地址:https://www.9cbs.com/read-23620.html

New Post(0)