Return performs one specific task: to return from the function that's currently being executed. In assembly, "return
" is simply boiled down to this:
That's it. However, if a function returns some value of some type, the value specified by the return statement is pushed onto the stack, followed by the destruction of all locally declared automatic storage, including parameters. Once all automatic storage has been popped from the stack, "ret
" is called and the CPU jumps back to the calling function, the caller.
Note that "main( )
" is a special function, but "return
" behaves the same way in all functions. In "main( )
" the value returned by the process can be any value within the range of "int
". To the OS, the value returned by the process is meaningless and the OS won't panic if a non-zero value is returned -- there are no standard return values except for "EXIT_SUCCESS
" and "EXIT_FAILURE
", but even the OS is unaware of these.