C function declaration (* (void (*) () 0 )();

Source: Internet
Author: User
When I look at some excellent open-source projects, I can always see various pointers and usage of various functions. I still have an obscure understanding of this aspect. today I will take the time to complement it.

When I look at some excellent open-source projects, I can always see various pointers and usage of various functions. I still have an obscure understanding of this. today I will take the time to complement it,

After turning over C language traps and defects, the following is a brief summary:

Let's take a look at a statement:

(* (Void (*) () 0 )();

We can only use metamorphosis to describe it. next we will analyze it step by step:

The simplest way to declare variables:

Int a; // declare a variable of the int type

Simplest function declaration method

Int fn (); // declares that the result type returned by the fn function is int.

The simplest method of pointer declaration:

Int * p = 0; // declare a pointer to the int type p, initialized to 0.

The function that returns the pointer:

Int * ();

The simplest method to declare function pointers:
Int (* h )();

H is a function pointer. what should I do if I want to forcibly convert the type?

In fact, it is very easy.

Simple type conversion:

12 Void * p = 10; printf ("% d \ n", (int *) p );

The function pointer is the same,

For example, what if we want to forcibly convert a function to an int (* h) () type function pointer?

You only need to (int (*) (expression...

What if I want to declare a (int (*) () type pointer function?

Step 1 declare a function pointer

Int (* )();

You only need to use (int (*) () as a type to forcibly convert.
(* (Int (*) () )()

It is actually a function pointer of the type (int ..

Related Article

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.