Fundamentally understand typedef

Source: Internet
Author: User

1. typedef int size_t;
Most books and teachers will talk about this statement. This is the alias for defining size_t as an int. That is, typedef a B. B is the alias of.
The result is correct, but it is not necessarily correct in terms of grammar. It cannot be understood as follows:

2. typedef int int_array [4];
Int_array A, B;
If you understand this, see:

3. typedef int (* PF) (const char *, const char *);
PF register (PF );
If you understand this, the following content is not prepared for you. If you do not understand, please refer to: (here I will try to explain it as much as possible)

If you think the following statement is troublesome:
Int A [4], B [4], C [4];
You want to simplify or hide complex types through the following statement:
Int_array A, B, C;
The method to use typdef is as follows:
1. Find the generic format you want to declare. For example, int A [4], B [4], C [4]; only A, B, and C are different, they have the same declarative mode int <Name> [4];
2. Use the new type name you want to declare to replace the change section in the general format. For example, the position of A, B, and C is replaced by the new type int_array, And the typedef symbol is added to the front, that is:
Typedef int int_array [4];
3. When you want to declare the, B, and C Types in the int_array position above, you can use the following statement:
Int_array A, B, C;

Simply put, in a defined typedef <string>;, an undefined type name type_a appears in the <string>. When you use this typedef:
The meaning of type_a object is that you actually declare to replace type_a in <string> with the object name.
For example, typedef int int_array [4];
Int_array object;
In fact, the statement you wrote is: Replace the string "int int_array [4];" with the int_array in the object to get the result: int object [4];
This is how the compiler processes the tyepdef definition.

After this explanation, you should easily understand the function pointer typedef. Is it very simple!

If you have read the original article, please leave a message in your reply ^_^

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.