[Mingw-users] gcc 8.2.0: missing _fileno() for c++11

Anton Shepelev anton****@gmail*****
Tue Jan 21 06:28:21 JST 2020


Keith Marshall to Anton Shepelev:

> > On the other hand, this worked with GCC 4.*...
>
> GCC-4.x with what options?

The same test case as posted, but with the GCC I had before
the upgrade.

> Eli is 100% correct -- -std=c++11 turns on strict ANSI,
> (or more correctly ISO-C++), conformance checking, and
> since fileno() is a POSIX.1 extension to ISO-C, (and
> _fileno() is a Microsoft specific equivalent extension),
> if you request strict ISO-C/ISO-C++ conformance checking,
> then either will be rightfully rejected.

Have you an idea why, then, fileno() is not rejected on
Linux with -std=c++11?  To be specific -- this program:

    #include <stdio.h>

    int main( void )
    {  FILE *f;
       f = stdin;
       fileno( f );
       return 0;
    }

compiles with -std=c++11?  Is it due to a bug or the
courtesy of developers?

> > Since the project I am trying to build and contribute to
> > is configured not to use the GNU extensions, I have to
> > find another way of acessing fileno/_fileno.
>
> But you are *already* depending on extensions, w.r.t. the
> standard of conformance which you are demanding.

I don't understand: comformance to C++11 does not imply a
dependency on an extension.  I am not sure, though, whether
it forbids one.  Judging by the behavior of gcc -std=c++11
on Linux, it does not.  Linux being a POSIX system, GCC has
no qualms about providing fileno() when asked to accept
C++11...

> If you want extensions, whether they be GNU or Microsoft,
> (or MinGW), don't specify "-std=c++11".

Understood.

> Why do you need to do so, anyway?  GCC-8 compiles C++11
> code by default, without requiring *any* "-std=..."
> restriction.

It is not me, whose task is small and tiny, but the
maintainers.  I believe their purpose is to avoid the
temptation to abuse non-standard features in general and GNU
extensions in particular.  Will ask them their reasons.
fileno() is POSIX of course, but there is no -stdPOSIX++11,
which I believe is why GCC on Linux accepts it in pure C++11
mode.

> > May I link it in manually from the MinGW library in
> > which it *is* implemented?
>
> Of course.  You will get it from the default C-runtime
> library, but you will need to explicitly declare it
> yourself.

I had already tried that:

#include <stdio.h>
int _fileno( FILE *stream );
int main( void )
{  FILE *f;
   _fileno( f );
   return 0;
}

but the linker fails with:

    undefined reference to `_fileno(_iobuf*)'

That is why I asked what additional linking may be required.



More information about the MinGW-Users mailing list