Legalize access to file descriptors now! (So sue me.)

Richard B. Kreckel kreckel@ginac.de
Thu Feb 17 23:54:00 GMT 2005


On Thu, 17 Feb 2005, Jonathan Wakely wrote:
[...]
>     "at least all the ugly stuff is completely hidden away inside a
>     compiled function and the interface is clear and pristine"
>
> Is that valid?  Doesn't a definition of fileno() have to be visible
> when it's used?

No.  The declaration is enough provided the correct instantiation is done
in some translation unit.  And that's what the template<> int
fileno<char>(const std::ios&) template specialization does.

> To achieve what you want fileno() would have to be a non-template
> function, overloaded for std::basic_ios<char> and
> std::basic_ios<wchar_t>.

You could do this, too.  It would just double the declaration where a
template is more concise.

>                          The definitions of those overloads could then
> use fileno_hack() which can be private to the file containing the
> function definitions.

Of course I've dodged the question what happens when the need for other
template instantiations arises.  People who use them are probably capable
enough to extend the code appropiately.  Another approach would be to just
expose the entire fileno_hack in the header file.  I've shied away from
this, though, for no hard reason.

  -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>



More information about the Libstdc++ mailing list