The quick_exit function terminates the process normally without completely cleaning the resources. It defined in the ‘stdlib.h’ header file, so you have to include the header file before using it.
The quick_exit function does not invoke the functions registered with atexit. But call the functions registered by the atexit function, in the reverse order of their registration.
Syntax quick_exit in C:
//Syntax of quick_exit _Noreturn void quick_exit(int status); // C11
Parameters:
status: Indicates whether the program terminated normally. It can be one of the following:
Value | Description |
---|---|
EXIT_SUCCESS | Successful termination |
0 | Successful termination |
EXIT_FAILURE | Unsuccessful termination |
Return:
The quick_exit function cannot return to its caller.
Let’s see an example code to understand the quick_exit function in C. Example code does not execute functions registered with at_quick_exit.
Note: Only C11 compiler, compile this code.
#include <stdio.h> #include <stdlib.h> void TestFunQexit (void) { puts ("Quick exit function."); } int main () { //registered function with at_quick_exit at_quick_exit(TestFunQexit); puts ("Main function: Beginning"); //called quick_exit() quick_exit (EXIT_SUCCESS); // never executed puts ("Main function: End"); return 0; }
Output:
Main function: Beginning
Quick exit function.
Important points related to the quick_exit function in C:
1. You must include stdlib.h header file before using the quick_exit function in C.
2. The quick_exit function does not invoke the functions registered atexit.
3. call the functions registered by the atexit function, in the reverse order of their registration.
4. If a program calls the quick_exit function more than once, or calls the exit function in addition to the quick_exit function, the behavior is undefined.
5. The status returned to the host environment is determined in the same way as for the exit function.
- If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned.
- If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned.
- In other cases, the implementation-defined status value is returned.
Recommended Articles for you:
- exit vs _Exit in C/C++
- Use of exit function in C/C++.
- atexit function in C/C++, you should know
- Use of abort function in C/C++ with Examples
- abs labs llabs functions in C/C++
- Best Gifts for the programmer and techies.
- List of best programming laptop.
- How to use and implement your own strcat in C.
- How to implement atoi in C/C++;
- Use and create strspn in programming.
- How to pass an array as a parameter?
- 10 Best C Programming Books.
- Best mouse for a programmer.
- How to make memcpy function in C
- memmove vs memcpy.
- Implement vector in C.