c - C中标准输出的方向是什么

标签 c

GNU C manual说:

Being able to use the same stream for wide and normal operations comes with a restriction: a stream can be used either for wide operations or for normal operations.

[...]

It is important to never mix the use of wide and not wide operations on a stream. There are no diagnostics issued. The application behavior will simply be strange or the application will simply crash. The fwide function can help avoiding this.

我已经在 vs2012 上试过了,一个 printf 紧接着一个 wprintf,这个简单的程序可以正常工作。

那么我的问题是,手册是什么意思?何时以及为什么我们应该使用 fwide 函数?

最佳答案

manual更完整地说:

Being able to use the same stream for wide and normal operations comes with a restriction: a stream can be used either for wide operations or for normal operations. Once it is decided there is no way back. Only a call to freopen or freopen64 can reset the orientation. The orientation can be decided in three ways:

  • If any of the normal character functions is used (this includes the fread and fwrite functions) the stream is marked as not wide oriented.
  • If any of the wide character functions is used the stream is marked as wide oriented.
  • The fwide function can be used to set the orientation either way.

It is important to never mix the use of wide and not wide operations on a stream. There are no diagnostics issued. The application behavior will simply be strange or the application will simply crash. The fwide function can help avoiding this.

请注意,Microsoft 文档说他们的 fwide()“未实现”(这是一个空操作)并且“不符合标准”。

我对这一切的理解是,使用 glibc 的程序不得在不重新打开单个流的情况下同时使用窄字符函数和宽字符函数。也许在 Microsoft 平台上没有这样的限制;甚至其他 libc 实现可能更灵活。

关于c - C中标准输出的方向是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19834506/

相关文章:

c - 客户端和服务器之间的 UDP 连接未在我的 Mac 上加载

c++ - 不释放内存是否可以接受

c - 该程序的运行时错误是什么?

c++ - 以编程方式创建带有 UI 的选项卡

java - libusb 与 USB 大容量存储器通信

c++ - VS 2015 编译器看不到 C 变量

c - 这是一个 C 程序,用于查找具有相同数字的下一个最大数字。但是没有通过一个测试用例

c++ - 编译时实际包含哪些文件

c - 如何在 C 中声明 32 位整数

c - Eclipse 中 gcc 编译器的默认标志