【发布时间】:2013-05-01 17:16:28
【问题描述】:
我正在查看 /usr/include/stdio.h
偶然发现了下面这段代码。
/* Standard streams. */
extern struct _IO_FILE *stdin; /* Standard input stream. */
extern struct _IO_FILE *stdout; /* Standard output stream. */
extern struct _IO_FILE *stderr; /* Standard error output stream. */
/* C89/C99 say they're macros. Make them happy. */
#define stdin stdin
#define stdout stdout
#define stderr stderr
我的问题是,这个结构 struct _IO_FILE 在哪里声明,我想看看布局。并且代码也提到了
#define stdin stdin
这应该如何工作?
【问题讨论】:
-
您使用的是什么操作系统/编译器?
-
操作系统: 3.2.0-41-generic-pae #66-Ubuntu SMP Thu Apr 25 03:50:20 UTC 2013
-
编译器: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
-
了解结构的外观并不像您预期的那样有用。它会因一个操作系统而异,甚至会因标准库的一个版本而异。您编写的任何依赖于这些内部细节的代码都将是非常不可移植的。如果您正在尝试完成特定的事情,可能会有更好的方法来完成它。
-
并没有试图让任何东西变得不可移植,这只是我在 Linux 中开发设备驱动程序时养成的习惯。您那里没有图书馆,所以您必须深入研究所有内容。