printf flush at program exit

前端 未结 4 1099
萌比男神i
萌比男神i 2020-12-16 17:54

I\'m interested in knowing how the printf() function\'s flush works when the program exits.

Let\'s take the following code:

int main(int         


        
4条回答
  •  心在旅途
    2020-12-16 18:13

    From man stdio on my machine here (emphasis added), whic runs RHEL 5.8:

    A file may be subsequently reopened, by the same or another program execution, and its contents reclaimed or modified (if it can be repositioned at the start). If the main function returns to its original caller, or the exit(3) function is called, all open files are closed (hence all output streams are flushed) before program termination. Other methods of program termination, such as abort(3) do not bother about closing files properly.

提交回复
热议问题