0

tengo una duda con los campos de la estructura FILE en C. Por ejemplo si accedo a los campos de esta estructura con MinGW32 5.1.4, obtendría el código de más abajo. Sin embargo, no sé cuales son estos campos con el compilador gcc, ya que esta estructura varía dependiendo del compilador. Soy principiante en este lenguaje, y no he podido encontrar la documentación adecuada. Si alguien me puede responder a esta duda se lo agradecería mucho. Saludos a todos...

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

1 respuesta 1

2

Extraido de StackOverflow en Inglés

Tal y como dices, según el compilador la estructura puede cambiar.

¿Cual es el motivo para saber la estructura interna? ¿Que quieres hacer?

Ten en cuenta el comentario en stdio.h que está justo encima del código que has puesto en la pregunta.

/*
 * The structure underlying the FILE type.
 *
 * Some believe that nobody in their right mind should make use of the
 * internals of this structure. Provided by Pedro A. Aranda Gutiirrez
 * <[email protected]>.
 */

Que traducido con traductor de google dice:

Algunos creen que nadie en su sano juicio debería hacer uso de las partes internas de esta estructura

Con gcc en Linux se usa glibc y está definido en libio.h

struct _IO_FILE {
  int _flags;       /* High-order word is _IO_MAGIC; rest is flags. */
#define _IO_file_flags _flags

  /* The following pointers correspond to the C++ streambuf protocol. */
  /* Note:  Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
  char* _IO_read_ptr;   /* Current read pointer */
  char* _IO_read_end;   /* End of get area. */
  char* _IO_read_base;  /* Start of putback+get area. */
  char* _IO_write_base; /* Start of put area. */
  char* _IO_write_ptr;  /* Current put pointer. */
  char* _IO_write_end;  /* End of put area. */
  char* _IO_buf_base;   /* Start of reserve area. */
  char* _IO_buf_end;    /* End of reserve area. */
  /* The following fields are used to support backing up and undo. */
  char *_IO_save_base; /* Pointer to start of non-current get area. */
  char *_IO_backup_base;  /* Pointer to first valid character of backup area */
  char *_IO_save_end; /* Pointer to end of non-current get area. */

  struct _IO_marker *_markers;

  struct _IO_FILE *_chain;

  int _fileno;
#if 0
  int _blksize;
#else
  int _flags2;
#endif
  _IO_off_t _old_offset; /* This used to be _offset but it's too small.  */

#define __HAVE_COLUMN /* temporary */
  /* 1+column number of pbase(); 0 is unknown. */
  unsigned short _cur_column;
  signed char _vtable_offset;
  char _shortbuf[1];

  /*  char* _save_gptr;  char* _save_egptr; */

  _IO_lock_t *_lock;
#ifdef _IO_USE_OLD_IO_FILE
};

struct _IO_FILE_complete
{
  struct _IO_FILE _file;
#endif
#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
  _IO_off64_t _offset;
# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
  /* Wide character stream stuff.  */
  struct _IO_codecvt *_codecvt;
  struct _IO_wide_data *_wide_data;
  struct _IO_FILE *_freeres_list;
  void *_freeres_buf;
# else
  void *__pad1;
  void *__pad2;
  void *__pad3;
  void *__pad4;
# endif
  size_t __pad5;
  int _mode;
  /* Make sure we don't get into trouble again.  */
  char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
#endif
};
3
  • El texto que citas, ... nadie en su sano juicio ..., yo lo habría puesto en mayúsculas, negrita, y, a ser posible, con una fuente extra-grande :-) +1
    – Trauma
    el 11 dic. 2018 a las 17:11
  • 1
    Lo de la negrita hecho ;-)
    – meegle84
    el 11 dic. 2018 a las 17:25
  • 1
    @meegle84 Y por mejorar un poco la traducción de Google, en vez de "la internos" yo pondría "las partes internas" o "las interioridades".
    – abulafia
    el 11 dic. 2018 a las 17:57

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.