简体   繁体   中英

Why does MSVC STL not implement sync_with_stdio()?

I looked for the implementation of this function in MSVC STL source on github, but found no code other than setting the synchronization flag.

Next, I wrote a simple program with a call to this function, and ran it under a debugger, hoping to find a reading of the address of this flag. But during the operation of the program, nothing reads this flag, except for the function itself.

Why didn't Microsoft implement this feature?

After that, I went to cppreference and was surprised by the detailed description of the function. Where does this information come from? It turns out that GCC is used in the cppreference examples, I went to look at libstdc++ source, where I found that this function is fully implemented.

Why did Microsoft decide to do this? Maybe their goal is to ensure the security and full synchronization of I/O streams?

"setting the synchronization flag" and returning the old one is all it is supposed to do as far as the standard goes: https://eel.is/c++draft/ios.base#ios.members.static-1

Otherwise, called with a false argument, it allows the standard streams to operate independently of the standard C streams.

"allows" doesn't mean "shall". It just means if you didn't call it with false , library is not allowed to buffer.

Cppreference says the same https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio

If the synchronization is turned off, the C++ standard streams are allowed to buffer their I/O independently

Microsoft here and LLVM here did not make use of the allowance and simply update the static boolean flag value that is not otherwise used. GNU libstdc++ is one current implementation that took a step further and gave unsynchronized C++ streams their own buffers here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM