为什么在gnu coreutils中stdout不等于1?
测试平台是32位x64 Linux,coreutils 8.5 在base64的源代码中,fwrite将使用stdout 要输出base64编码的字符串为什么在gnu coreutils中stdout不等于1?,c,stdout,libc,gnu-coreutils,C,Stdout,Libc,Gnu Coreutils,测试平台是32位x64 Linux,coreutils 8.5 在base64的源代码中,fwrite将使用stdout 要输出base64编码的字符串 当我使用ltrace打印所有libc调用时,我们可以看到stdout等于0xb772da20 __libc_start_main(0x8048eb0, 2, 0xbf892f74, 0x804cb50, 0x804cbc0 <unfinished ...> strrchr("base64", '/')
__libc_start_main(0x8048eb0, 2, 0xbf892f74, 0x804cb50, 0x804cbc0 <unfinished ...>
strrchr("base64", '/') = NULL
setlocale(6, "") = "en_US.UTF-8"
bindtextdomain("coreutils", "/usr/share/locale") = "/usr/share/locale"
textdomain("coreutils") = "coreutils"
__cxa_atexit(0x804a3b0, 0, 0, 0xbf892f74, 2) = 0
getopt_long(2, 0xbf892f74, "diw:", 0x0804d1a0, NULL) = -1
fopen64("testbase64", "rb") = 0x8591878
fileno(0x8591878) = 3
posix_fadvise64(3, 0, 0, 0, 0) = 0
fread_unlocked(0xbf89225c, 1, 3072, 0x8591878) = 900
fwrite_unlocked("Ly8gcXVpY2tTb3J0LmMKI2luY2x1ZGUg"..., 1, 76, 0xb772da20) = 76
grep stdout *.h
我看不到任何预定义的stdout
有谁能帮我解释一下为什么stdout将被定义为“0xb772da20”,而不是1,而不是0?根据,stdout是一个指针(指向某个文件
不透明结构),因为它是一个文件流。它不是文件描述符。它的文件描述符是
STDOUT\u FILENO
它实际上是1
在我的Gnu libc Linux系统上,我在/usr/include/stdio.h
的第169行附近:
/* 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
在此之前(第48行)有
另请参见一个相关问题。根据,标准输出是一个指针(指向某个文件
不透明结构),因为它是一个文件流。它不是文件描述符。它的文件描述符是
STDOUT\u FILENO
它实际上是1
在我的Gnu libc Linux系统上,我在/usr/include/stdio.h
的第169行附近:
/* 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
在此之前(第48行)有
另请参见相关问题。相关:要打印指针值,请将其强制转换为
void*
。这通常无关紧要,但不能保证void*
和其他指针类型具有与参数相同的表示形式或以相同的方式传递<代码>printf(“%p\n”,(void*)标准输出)代码>相关:要打印指针值,请将其强制转换为void*
。这通常无关紧要,但不能保证void*
和其他指针类型具有与参数相同的表示形式或以相同的方式传递<代码>printf(“%p\n”,(void*)标准输出)代码>
typedef struct _IO_FILE FILE;