有时&QUOT方案为何;跳过"用printfs? [英] Why do programs sometimes "skip over" printfs?

查看:107
本文介绍了有时&QUOT方案为何;跳过"用printfs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

if (!strcmp(ent_child->d_name, "eeprom")){
    printf("\tread_from_driver: found a match! ");//DEBUG
    get_child_path(child_path, child_path, "eeprom");
    printf("The path is: %s\n", child_path);//DEBUG
    read_eeprom(child_path);
}

这会导致在某些时候段错误,(大概get_child_path),但第一个printf不会发生,即使当我修复code是这样的:

This causes a segfault at some point, (probably get_child_path), but the first printf never happens, even though when I fix the code to be this:

if (!strcmp(ent_child->d_name, "eeprom")){
    while(1)
         printf("\tread_from_driver: found a match! ");//DEBUG
    get_child_path(child_path, child_path, "eeprom");
    printf("The path is: %s\n", child_path);//DEBUG
    read_eeprom(child_path);
}

它确实发生。这是怎么回事?这绝对不是我第一次观察到这种行为。

It does happen. What's going on? This is definitely not the first time I observed this behavior.

推荐答案

标准输出行缓冲的默认情况下,这意味着你只获得更新的输出,当你发送一个换行符,或当你明确地调用 fflush(标准输出)

stdout is line-buffered by default, which means that you only get updated output when you send a newline character, or when you explicitly call fflush(stdout).

这篇关于有时&QUOT方案为何;跳过"用printfs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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