typedef :
If it is placed outside all functions, its scope is from the beginning of its definition until the end of the file;
If placed within a function, the defined field is defined from the beginning of the definition until the end of the function;
#define :
Scopes are defined from the beginning of the definition to the end of the entire file, whether within a function or outside of all functions.
Such as:
typedef ...//Start here to end of file
#define ...//start here to end of file
int negate (int num)
{
...
typedef ...//Start here to the end of the function. Note that in this function, before this definition, it cannot be used
#define ...//start here to end of file
...
}
typedef ...//Start here to end of file
#define ...//start here to end of file
void Show ()
{
typedef ...//Start here to the end of the function.
#define ...//start here to end of file
}
...
Summarize:
(1) Whether it is a typedef or a define, it cannot be used before the definition;
(2) the typedef is affected by the function range, and the define is not affected;
(3) whether it's a typedef or define ? , its scope does not extend to other files, even different files of the same program, and cannot be used with each other.
Scope of typedef and define