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.
您是否正在进行优化编译-因为printfs / assert的实际顺序可能不符合您的期望。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.