I Wanna know the Internal Members of struct FILE, the latest ones

后端 未结 3 1853
情歌与酒
情歌与酒 2020-12-17 01:01

When I read pg.176 of The C programming Language by K&R, I was very excited. I found all the members of struct FILE ( which I was searching for ) and its just awesome to

3条回答
  •  生来不讨喜
    2020-12-17 01:07

    The internal members change according to your compiler

    As unwind said, you should look in your compiler's library code (in your case, GCC, which uses glibc).

    The fileno "function" is actually a macro and is defined in MinGW (in stdio.h) like this :

        #define fileno(__F) ((__F)->_file)
    

    Note that MinGW is based upon GCC, and shouldn't have compatibility problems.

    Since it's a macro, you should be able to find it in your standard library by searching for "#define fileno" in your include folder. It is most likely defined in the stdio.h header.

    Also, to answer your original question, here are the internal members of FILE as defined within stdio.h in GCC/MinGW :

        typedef struct _iobuf
        {
            char*   _ptr;
            int _cnt;
            char*   _base;
            int _flag;
            int _file;
            int _charbuf;
            int _bufsiz;
            char*   _tmpfname;
        } FILE;
    

    tldr : in minGW/GCC, use fp->_file. Look at rest of post if you're using a different compiler

提交回复
热议问题