FILE*的内容代表什么

What is represented by the content of 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 如果不使用文件描述符怎么办?

What does the value of FILE* represent?

它是一个指向FILE结构的指针,对于glibc它的定义是here. Which, among other things, contains the file descriptor. You can get the file descriptor from FILE* using POSIX fileno函数。

有关更多详细信息,您可能希望查看 Interaction of File Descriptors and Standard I/O Streams