Typedef int * pint; // occurs during compilation
It is equivalent to an int * with an alias. It can be used to define an integer pointer and is also a type name.
Pint p, q; // p, q all point to int type pointer
# Define pINT int * // occurs in the pre-compilation phase
Only simple macro replacement
Such as pINT p, q
Replace it with int * p, q; // p is the pointer, while q is only an integer variable.
Typedef is not a simple replacement
The description in MSDN is as follows:
Visual Studio 2010-Visual C ++ Typedef Declarations
A typedef declaration is a declaration with typedef as the storage class. the declarator becomes a new type. you can use typedef declarations to construct shorter or more meaningful names for types already defined by C or for types that you have declared. typedef
Names allow you to encapsulate implementation details that may change.
A typedef declaration is interpreted in the same way as a variable or function declaration, but the identifier, instead of assuming the type specified by the declaration, becomes a synonym for the type.
Note that The declaration of The declarator becomes a new type. Note that it is a new type (1)
But what are the synonyms of becomes a synonym for the type? (I have not learned English well)
So can we use typedef INT int?
Then unsigned INT a = 1; // The answer is No if it is the same as unsigned int a = 1.
In this way, it cannot be passed in vc2010. In my understanding, the unsigned int type can also be written as unsigned,
Int Is also a type. The unsigned int type is not a combination of the unsigned type and int type, because int is signed and the former is unsigned.
INT is a new type (as mentioned above (1). An unsigned INT attempts to combine the two types will certainly cause an error.
Why can unsigned int be used? Because it is a data type, not a combination of the two data types.
As mentioned above, when typedef occurs during compilation, the compiler does not know the unsigned INT. It only knows the unsigned int.
# Define INT int
Unsigned INT Is simply replaced with unsigned int in the pre-compilation phase. In the compilation phase, the compiler sees that the unsigned int is of course no problem.
The key is to understand that the unsigned int is a data type, not a combination of the two data types unsigned and int.