True understanding of TypedEf

xiaoxiao2021-03-17  195

I have been learning C for three years, or I am not very familiar with Typedef. I finally figured out today, so I published this post, I hope that I can help it for less clear friends. First, please see the following two sentences: typedef int a [10]; typedef void (* p) (void); if you can see what they mean, please don't look down again. If you don't understand, or the concept is still blurred, please continue to see it. I will stick someone to the things directly below. I'm too slow. Ha ha. Original (excerpt): typedef is used to declare an alias, the syntax behind TypeDef is a statement. Originally, I didn't misunderstand this here, but the result was unexpected, and people who misunderstand were not in a small number. The culprit is also the harmful textbook. The following form is usually written when introducing TypeDef in these textbooks: Typedef int Para; this form is almost the same as #define int para, as described in the previous chapter, these textbooks is to be deep, but actually The behavior is to be biased. Indeed, this form is the easiest in all forms, but there is no further explanation for TypedEf, making many people to look at Typedef with #define, and separate INT and PARA, int is part, Para is another Part of it, but actually is not such a thing. INT and Para are a whole! Just like the INT i: declaration is an overall statement, but INT i defines a variable, and Typedef defines an alias. These people will not understand some statements as follows: typedef int a [10]; typedef void (* p) (void); they will think that A [10] is an alias of Int, (* p) (void) is the alias of Void, but such an alias does not seem to be a legal name, so it is caught in confusion. In fact, the above statement is declared as a type alias having 10 INT elements, and P is a type alias of a function pointer. Although Typedef can be seen as actions separated from int Para, TypeDef is a storage class declaration specifier, so strictly, TypeDef Int Para is a complete statement.

Define a function pointer type. For example, the original function is a Void function; then the defined function pointer type is TypeDef Void (Void); then generates a pointer to the function with this type: fun func1; after the FUNC1 is obtained, then you You can use this function pointer to call the original function: Func1 (Void);

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

New Post(0)