[libcxx-dev] Question on how libc++ defines cin and other streams
Louis Dionne via libcxx-dev
libcxx-dev at lists.llvm.org
Wed Nov 28 08:36:38 PST 2018
Hi,
In src/iostream.cpp, I can find the following beautiful declarations:
_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream at DU?$char_traits at D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12 at A")
#endif
;
// etc...
And then we have this a little lower in src/iostream.cpp:
_LIBCPP_HIDDEN ios_base::Init __start_std_streams;
ios_base::Init::Init() {
istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin));
// ...
}
I understand we're basically allocating a char array and then placement newing the stream into it during static initialization. However, why is that dance necessary with Clang-on-Windows?
Thanks,
Louis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20181128/915f8326/attachment.html>
More information about the libcxx-dev
mailing list