vdudouyt / stm8flash

program your stm8 devices with SWIM/stlinkv(1,2)
GNU General Public License v2.0
401 stars 182 forks source link

Fix text output in stm8flash to display immediately #155

Open bp-dl opened 1 year ago

bp-dl commented 1 year ago

When running stm8flash from within another IDE (such as Code::Blocks), any text that is output does not get displayed in the IDE until stm8flash exits (due to a lack of a flush). This commit fixes this by wrapping the text output calls in a macro that flushes the output stream each time. With this fix, the text output is displayed as stm8flash is running, and you are able to see it's progress in real time.

schneidersoft commented 1 year ago

Rather than using a macro please use a dedicated function to wrap text output. I've never looked into this, but I suspect that there might be a simpler way to make the stdout automatically flush

schneidersoft commented 1 year ago

A little googling shows that setvbuf(stdout, NULL, _IONBF, 0) can be used to make stdout unbuffered... just like stderr.

The stream stderr is unbuffered. The stream stdout is line-buffered when it points to a terminal. Partial lines will not appear until fflush(3) or exit(3) is called, or a newline is printed. This can produce unexpected results, especially with debugging output. The buffering mode of the standard streams (or any other stream) can be changed using the setbuf(3) or setvbuf(3) call.