This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Legalize access to file descriptors now! (So sue me.)
On Thu, Feb 17, 2005 at 11:27:05PM +0100, Richard B. Kreckel wrote:
> 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.
Ah, yes, I see. Although 14/8 in the standard says:
A non-exported template must be defined in every translation unit in
which it is implicitly instantiated (14.7.1 temp.inst ), unless the
corresponding specialization is explicitly instantiated (14.7.2
temp.explicit ) in some translation unit; no diagnostic is required.
[Note: See also 14.7.2 temp.explicit ]
template <C,T> fileno() is implicitly instantiated in any translation
unit that uses it. Assuming it is only instantiated for std::ios and
std::wios the corresponding specialisations are defined in some other
translation unit, but they're _not_ explicitly instantiated.
To be completely conforming, do you need to add explicit instantiations
to the .cc file, like so?
template int fileno<char>(const std::ios& stream);
template int fileno<wchar_t>(const std::wios& stream);
jon
--
"There are only two industries that refer to their customers as 'users'."
- Edward Tufte