Typedef int (init_fnc_t) (void) and typedef int (* init_fnc_t) (void)

Source: Internet
Author: User

1. typedef int (init_fnc_t) (void); it indicates that init_fnc_t is defined as the function type. This function returns int type and has no parameter.
"init_fnc_t * init_sequence [] = {cpu_init, board_init}" indicates that a one-dimensional pointer array is defined using init_fnc_t (function type). All elements in the array are pointer variables, they all point to function pointers. The return values of these functions are int type and have no parameters. More clearly, each element in the array is used to store the first address of the function entry.

2. INT (* init_fnc_t) (void); defines a function pointer (Return Value: int type, no parameter function pointer, stores the first address of the function ), typedef int (* init_fnc_t) (void); indicates defining a function pointer type. You can use the init_fnc_t symbol to define the function pointer. "init_fnc_t init_sequence [] = {cpu_init, board_init} "indicates that an array is defined using init_fnc_t (function pointer type). All elements in the array are a function pointer, cpu_init,
Board_init is a function pointer and stores the first address of the function.

In summary, I personally think the two definitions mean the same thing, but they are written differently. The array element in 1 is the pointer variable pointing to the function, the elements in array 2 are function pointers. The result is the same.

To be honest, the usage of typedef is really abnormal, and a careful one will let you fall into the trap !!! However, I think my personal C language skills will be greatly improved if I can make good use of typedef and deeply understand his connotation!


------------------------------------ Reprint------------------------------------

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.