开发者

printf before assert doesn't work

I think I've seen this issue before and I bet there's better solution out there 开发者_开发知识库so asking..

During debugging I found that any printf before assert don't work well. They're simply not printed most of the time. I tried adding fflush(stdout) but it doesn't seem to help.

Any other thoughts or alternatives?

Example:

printf... <- not printed
printf... <- not printed due to the assert. stdout not flushed?

do something

assert()


Call fflush(stdout) before assert. Or, if stdout has not been redirected and refers to the terminal, just writing a newline at the end of your message should be sufficient. By default, stdout is buffered (line buffered on terminals; fully buffered otherwise) and thus output will not actually be written until the output buffer overflows or a newline (in line-buffered mode) or fflush is encountered.


Are you compiling with optimization - because the actual order of the printfs/assert may not be what you expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜