Compiling a C program with g++ 4.3.1 yields an error about std::FILE

Marc Glisse marc.glisse at
Tue Jul 22 17:04:57 CEST 2008

On Mon, 21 Jul 2008, Torbjorn Granlund wrote:

>  So, this is what you're suggesting:
>  At the beginning of the file:
>  #if defined (__cplusplus)
>  #include <iosfwd>   /* for std::istream, std::ostream, std::string */
>  #include <cstdio>
>  #endif
>  And around line 520:
>  #if defined (__cplusplus)
>  extern "C" {
>  using std::FILE;
>  #endif

Yes. That would IMHO be strictly better than what you (or debian) were 
doing in the previous email. The "using std::FILE" could even move next to 
the "include cstdio" but that is just esthetics so never mind.

(I don't even remember if there is a compiler that fails without this 
using std::FILE (only sunpro on solaris and a theoretical perfect standard 
compiler AFAIK) and for which this using is sufficient (size_t and va_list 
are also in std:: normally), but I am just going for the minimal changes)

> In C, we require users to include stdio.h for getting GMP I/O function
> prototypes.  These changes include stdio for C++.  Shouldn't we
> require the user to include it, like in C?

That is an other question. In previous discussions we heard many users who 
wanted it by default and none who didn't want it, so I guess the reasons 
to make it optional in C (lighter, or stdio not even implemented) are less 
relevant for C++ (though they could be). But again it is your choice, the 
meaning of my email was just that if you wanted to include cstdio by 
default, the best place to include it was at the beginning.

(I heard someone suggest to reverse the logic by including stdio by 
default, even for C, unless a macro GMP_NO_STDIO was defined by the user. 
That could be confusing to old code that relies on the absence of 
stdio, but I think the idea was that people working in this kind of 
environment have a better idea of what they are doing than beginners on 
a regular windows/mac/linux PC. I have no idea, minimizing the noise on 
this list is not the worst criterion...)

If you are in the process of doing C++ portability patches, one I find 
very important is the one about freefunc in gmpxx.h (use a typedef in 
extern "C"). There are several versions by different people on the list 
(it is just a couple lines), I can resend one if needed. The thing is that 
all the std:: mess in gmp.h is easy to work around by including the C 
headers (stddef.h, stdio.h, don't know which ones exactly) or some "using" 
directives before gmp.h, never mind the pollution of the global namespace, 
whereas I have to patch gmpxx.h before I can use it.

Marc Glisse

More information about the gmp-bugs mailing list