stdio line-streaming revisited
Sean Kelly
sean at f4.ca
Thu Mar 29 16:04:05 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
>
> So what's the recommended use of Cout?
>
> (a) If you do stdio, use Cout (and don't forget to flush Cout manually
> every time you plan to read from Cin).
Oh right, this is what tie() is for with iostreams. It's come up before
in the past, though I can't recall if any conclusions were reached.
I'll admit that the current behavior is a tad confusing here though.
> (b) But not for multithreaded programs that do stdio. For those, use the
> logger facility. If you want multithreaded output to stdout, copy the
> code from http://www.dsource.org/projects/tango/wiki/ChapterLogging into
> your program. Be careful that that code might be incorrect; the manual
> doesn't specify. If it is correct, be careful with what you do inside
> that code, because you could deadlock yourself.
To be fair, this is mostly a documentation issue. Though it may be that
the logger could be made easier to use for your example. I'll have to
look at the logger in more detail before I say any more--I've only used
it a handful of times.
> (c) And not for programs linking with anything that uses C's stdio. For
> those, use Phobos.
Perhaps more accurately "programs that expect to mix output to the same
device as linked libraries using C's stdio." I can't recall ever
needing this option, YMMV (and it obviously does). One option might be
to create a CStdioCondiuit or some such that uses C library calls
instead of platform calls for IO. Then the user could choose the
appropriate one.
I think it's also perhaps worth noting that Tango is truly intended to
be as much of an application framework as it is a collection of useful
tools. In fact, some non-essential features have been deliberately
excluded to avoid discouraging third-party development. I would also
personally consider C stdio integration to be a specialized need for the
typical D programmer, and therefore it is arguably not appropriate as
the default configuration for Tango's IO layer if doing so incurs design
or performance penalties (both of which seem to be the case, based on
recent experimentation). Therefore, I am not convinced that C
integrated IO should be the default behavior for Tango's Cin/Cout, and
feel it may be better offered as a separate conduit or handled some
other way. My opinion may well change if this proves to be a real issue
for many people, but that's my gut feeling at the moment.
Sean
More information about the Digitalmars-d
mailing list