Is it safe to disable buffering with stdout and stderr?

前端 未结 5 456
我寻月下人不归
我寻月下人不归 2021-02-03 11:01

Sometimes we put some debug prints in our code this way

printf(\"successfully reached at debug-point 1\\n\"); 

some code is here

printf(\"successfully reached          


        
5条回答
  •  [愿得一人]
    2021-02-03 11:21

    why all stream are by default line buffered

    They are buffered for performance reasons. The library tries hard to avoid making the system call because it takes long. And not all of them are buffered by default. For instance stderr is usually unbuffered and stdout is line-buffered only when it refers to a tty.

    then is this safe to do this?

    It is safe to disable buffering but I must say it's not the best debugging technique.

提交回复
热议问题