The time of the function is different
The typedef works in the compile phase, so there is the function of type checking.
define in the preprocessing phase function ( before compilation), with a simple string substitution without type check.
Second, different Functions
typedef
(1) aliases for defining types
(2) Define machine-independent types
(for example, to define a floating-point type called REAL, it can get the highest precision on the target machine: typedef long double REAL;
So long is not supported On a double machine, the typedef would look like this: typedef double REAL;
even double On a machine that is not supported, the typedef looks like this: typedef float REAL;)
Define
(1) alias the type
(2) define constants, variables, compilation switches
Third, different scopes
#define没有作用域的限制, as long as it is a previously predefined macro, can be used in future programs. And the typedef has its own scope.
Four, manipulation of pointers
<span style= "FONT-SIZE:14PX;" >typedef int * pint; #define PINT int * </span>
<span style= "FONT-SIZE:14PX;" >const Pint p;//p cannot be changed, p-pointing content can be changed, equivalent to int * const p; Const PINT p;//p can be changed, p-pointing content cannot be changed, equivalent to const int *P, or int const *p; PINT s1, S2;//equivalent to <span style= "font-family: ' Times New Roman '; line-height:19.5px; Background-color:rgb (250, 247, 239); " >int *a; int *b;</span> i.e. both are pointers pint S3, S4;///equivalent to <span style= "font-family: ' Times New Roman '; line-height:19.5px; Background-color:rgb (250, 247, 239); " >int *a, B; Only the former is the pointer </span></span>
For more details, see "the detailed differences between typedef and define"
Define and typedef differences