在程序退出的printf平齐 [英] printf flush at program exit

查看:117
本文介绍了在程序退出的printf平齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用的printf()函数的冲洗工作,当程序退出。

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

让我们采取以下code:

Let's take the following code:

int main(int ac, char **av)
{
    printf("Hi");
    return 0;
}

在这种情况下,如何做的printf()管理​​刷新其缓冲区标准输出

In this case, how does printf() manage to flush its buffer to stdout?

我想这是与平台相关的,所以让我们的Linux。

I guess it's platform dependent, so let's take Linux.

这可以用 GCC __属性__((析构函数))但随后的标准库将实施编译器相关的。我想这是不是它的工作方式。

It could be implemented using gcc's __attribute__((dtor)) but then the standard library would be compiler dependent. I assume this is not the way it works.

任何解释或文档链接是AP preciated。谢谢你。

Any explanations or links to documentation is appreciated. Thank you.

推荐答案

C运行时将注册的atexit()处理程序来刷新标准缓冲液时退出()被调用。

The C runtime will register atexit() handlers to flush standard buffers when exit() is called.

请参阅此解释

这篇关于在程序退出的printf平齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆