Skip to content
Advertisement

How do I fix “‘struct _IO_FILE’ has no member named ‘_file'”?

I have a version of a program that used to compile to a *.o file, but now it does not, and gives a compiler error.

I have tried to compile my code with gcc compiler on Linux, and the compile fails.

JavaScript

I expect the command gcc -c isatty.c to yield isatty.o but it does not. Instead, I get this message:

JavaScript

Advertisement

Answer

Never use any members of the FILE structure.

Use fileno(stdin) instead of stdin->_file.

The member _file is a MinGW-specific name for the file descriptor, while fileno is a widely-supported POSIX-compliant function.

Along with that, you may want to #include <unistd.h> instead of defining isatty explicitly.

If you’re limited to writing your code this way for some reason, don’t expect it to be portable. Otherwise, this should work:

JavaScript

What this changes is that it includes unistd.h which provides a declaration for isatty, it includes the types of the arguments within the function definition, and it uses fileno(stdin) instead of stdin->_file, of which the former is much more portable. It also improves the formatting so others can read your code if they need to.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement