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.