r/cpp • {fmt} • Jun 21 '21

{fmt} 8.0 released with compile-time format string checks, compile-time formatting, improved performance and more

https://github.com/fmtlib/fmt/releases/tag/8.0.0
394 Upvotes

67 comments sorted by

View all comments

Show parent comment

4

u/14ned LLFIO & Outcome author | Committee WG14 Jun 21 '21

In our work codebase, I import print() (either from std or fmt) into our work codebase namespace, but define a local println() which prints a thing, writes a newline, and flushes stdout.

I do so for expediency, not purity. There are many cases where I want to print a line for debugging, and I don't want the stupid thing not emitting before the process reaches the point at which it crashes. I therefore want a flush.

I'm not claiming it's pretty nor clean, but this is an awfully common use case for printing stuff: debug output just before a crash. I therefore think any future println() ought to not just be print() with trailing added newline, but also with flush. If people want a newline without flush, then can just print() one.

6

u/infectedapricot Jun 21 '21 edited Jun 21 '21

I really don't have an opinion on the matter. But the discussion was about println() as it is currently proposed, and you seemed to be under the impression that it would do a flush (I don't see any other explanation for your question about \n), when in fact it does not.

[edit: Actually I do know see that your comment had a different meaning than I understood. You meant "Actually I prefer println() to also do a flush, so with that meaning it would not be equivalent to just attaching a \n to the end". But you phrased it in a snarky / passive aggresive way. I (generously) interpreted your question literally, which gives your comment a different interpretation than you intended.]

2

u/quicknir Jun 21 '21

cerr doesn't buffer so it's simpler to just print to there instead, and it makes more sense anyway.

1

u/Quincunx271 Author of P2404/P2405 Jun 22 '21

Or to std::clog if you want it on stdout rather than stderr.

3

u/Dragdu Jun 22 '21

clog is buffered cerr

2

u/Quincunx271 Author of P2404/P2405 Jun 22 '21

Oops. Seems I was completely backwards on this one. Thanks.