Function pointer and variable length parameter list

Source: Internet
Author: User

For exampleCodeFragment:


Int add (int A, int B) {return a + B;} void my_test (int * val, INT (* func) (INT, INT) {int A = 100, B = 200; * val = func (a, B);} void my_test2 (int * val ,...) {int A = 100, B = 200; int (* func) (INT, INT) = * (INT (**) (INT, INT )) (& Val + 1); * val = func (a, B);} int main (INT argc, char ** argv) {int val1 = 0, val2 = 0; my_test (& val1, add); printf ("val1: % d \ n", val1); my_test2 (& val2, add); printf ("val2: % d \ n ", val2); Return 0 ;}

Note: In my_test2, use a pointer pointing to the function pointer to take the value from the stack.

Note: The method here is very bad. varargs is used for variable parameters. Here is just an example.


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.