Function pointer, callback function, system call difference, callback function system call

Source: Internet
Author: User

Function pointer, callback function, system call difference, callback function system call

Differences between function pointers, callback functions, and system calls
1. function pointer

1 int add (int a, int B) 2 {3 return a + B; 4} 5 6 int (* fp) (int, int); 7 8 int main () 9 {10 int c; 11 fp = add; // There is a pointer assignment operation, static binding 12 c = fp (2, 4); 13 printf ("c = % d \ n ", c); 14 return 0; 15}

2. Callback Function

1 int add (int a, int B) // callback function 2 {3 return a + B; 4} 5 6 int fun (int a, int B, void (* fp) () // intermediate function, dynamically bound, related to the passed function name 7 {8 return fp (a, B); 9} 10 11 int main () 12 {13 int c; 14 c = fun (2, 4); 15 printf ("c = % d \ n", c); 16 return 0; 17}

Embodiment: 1. Pass the function name as a parameter to the called function.

2. Separate the caller from the called function. The callback function implements specific functions. The caller does not need to pay attention to the specific implementation details.

3. System Call
System Call --> (0x80) Soft Interrupt (system call table) --> kernel function --> return to System Call Layer

Read --> system call number -- kernel function entry --> Implementation function --> return the call result

Implementation Method: Implement Through interrupt and use register to transmit Parameters

The process has gone through switching from the user State to the kernel state. After the processing is complete, it is restored to the user State to continue completing the system call.

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.