什么是由FILE的内容*

我有这个程序

#include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <fcntl.h> int main(void) { FILE* f = fopen("/Users/user/a.cc", "rb"); printf("%i\n", f); // 1976385616 printf("%i\n", *f); // 1976385768 int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); printf("%i\n", sockfd); // 4 fclose(f); close(sockfd); int fd = open("/Users/user/a.cc", O_TRUNC | O_WRONLY, 0); printf("%i\n", (int) fd); // 3 close(fd); } 

我知道34代表0,1,2为stdinstdoutstderr文件描述符fopen显然不使用文件描述符。

FILE*的值代表什么? 如果不使用文件描述符, fopen如何?

FILE *的值代表什么?

它是一个指向FILE结构的指针,对于glibc,它的定义就在这里 。 其中包含文件描述符。 您可以使用POSIX fileno函数从FILE*获取文件描述符。

有关更多详细信息,可能需要查看文件描述符和标准I / O流的交互 。