C language complex type declaration how to understand?

xiaoxiao2021-03-05  30

Q: What does Float (* op [4]) (FLOAT A, FLOAT B) mean? What should I analyze the C language complex grammar statement Main Solution: Pluskid Submit: BNGFCY Thank: Pluskid, Jimychen, Yangsongx review: Flood1984 Community Correspondence Post: View A: State: Float (* OP [4]) (Float A, Float B); what is the representative? What do you mean? -------------------------------------------------- ------------- Next is a pointer, pointing to a function, the function returns another pointer, the pointer [The function returns] points to a constant pointer to a type CHAR. -------------------------------------------------- ------------- Pointer array of functions! ! -------------------------------------------------- ------------- The statement is correct ------------------------------- ------------------------------ Everyone has a headache that only the compiler likes only the compiler. In fact, It is regular. Just follow the priority analysis of the statement. The priority rules of the C language declaration are as follows: ----------------------------------------- ---------------------- A statement begins to read from its name, then read the B priority from high to low according to the priority order : B.1 Declaration of the part of the B. 2 suffix operator parentheses [Parentheses "is a function, square bracket [] means this is an array] B.3 prefix operator [* indicates this Is a pointer pointing ... C whose followback is tight with the specifier [such as int, long, etc.), then it acts on the type specifier. In other cases, const and [or] volatile keyword act on its left side adjacent pointer as an asterisk. -------------------------------------------------- -------------- Next example: char * const * (* next) (); -------- ------------ ------------------------------------------ Application rules explain ----- ---- ----------------------------------------------- ------ A First, look at the variable name "Next", and notice that it is directly hosted by brackets to see the things inside the brackets into a whole, "Next is a pointing ... The pointer "B then considers what is outside the brackets, and makes a choice of B.2 B.2 rules between the asterisk prefix and the brace suffix tell us that the priority is the function parentheses, so" Next is a function. Pointer, point to a function of returning ... B.3 then process the prefix "*", draw the content C whose pointer is final, interpreted "char * const" as a constant pointer to the character ------ - - ------------------------------------------------ ------ After the above analysis, "NEXT is a pointer, which points to a function, the function returns another pointer, the pointer [The function returned] points to a constant pointer to a type CHAR."

Don't be troublesome, you will naturally see all kinds of statements, such as what you ask: float (* op [4]) (Float A, Float B); with the above steps, you can get "OP is an array containing four elements. The type of element is a pointer, which is a function pointer, which accepts two float parameters, and returns float." In fact, using the above rules, it can be easily written A small procedure for analyzing C language declarations, there is a ready-made use, it translates the C language to English [Don't suspic the code too mess, it has been tired, after all, this is the International C language chaos code competition Winning works. ^ _ ^]: Cdecl.c -------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ # include # include

#define w printf #define p while #define t (s) (w = t (s)) char * x, * b, * l, i [99]; m, w, v; d () {w == 9? ("'%. * S'is", v, x), t (0)): w == 40? (T (0), d (), t (41)): w == 42? ​​(T (0), D (), w ("ptr to")): 0; p (w == 40? (T (0), w ("func return", t (41)): W == 91? (T (0) == 32? (W ("Array [0 ..% D] of", ATOI (X) -1), T (0)): w ("array of") , T (93)): 0);} main () {p (w ("INPUT:"), b = gets (i)) IF (t (0) == 9) l = x, m = v, T (0), D (), w ("%. * s./n", m,} t (s) {if (! s | | s == w) {p (* b == 9 | * b == 32) B ; x = b; v = 0; if (w = isalpha (* b)? 9: Isdigit (* b)? 32: * b ) IF (W <32) P (isalnum (* b)) B , V ;} returno w;} -------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- The above content Self-"Expert C Programming" This is a good book, It is recommended that people who have not seen it go to see it.

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

New Post(0)