marc.glisse at normalesup.org
Mon Dec 17 11:10:39 CET 2007
On Sun, 16 Dec 2007, Richard B. Kreckel wrote:
> There's this line in gmp.h.
It has been discussed last week on this list...
> But std::FILE hasn't been defined and with a conforming C++ compiler it
> won't be unless <cstdio> has been included before <gmp.h>.
This line is protected by a test that a variable like STDIO_H is defined,
so it is only read if stdio.h or cstdio was included before gmp.h.
> Note that
> including <stdio.h> is not enough, as it doesn't define namespace std.
That is a bug, the current standard says it should (that may change in the
next standard, but hasn't yet).
> So, defined(__cplusplus) and including <stdio.h> is not enough to
> guarantee that std::FILE is known to the compiler.
It should be. A ridiculous workaround would be for gmp.h to include cstdio
when it detects that either stdio.h or cstdio was included in c++.
> Apparently, the intent is to avoid including stdio.h or cstdio. Why? I
> would suggest including it.
I think it is because stdio is not present on all targets supported by
gmp, and even when it is it uselessly (when you don't use it) makes the
whole program more heavy. I agree this last is not very relevant for a
shared libgmp linked to a shared libc (or usually for C++).
> Besides, these using declarations are considered bad practice in header
> files. It would be better defining GMP_FILE or similar to either expand
> to FILE or std::FILE and use that instead of FILE.
And doing the same for std::size_t, std::ptrdiff_t, etc. There was a patch
on the list after 4.2.1 to do that, but it wasn't adopted.
Now it may still be a good idea to include cstdio by default in c++ mode
in gmp.h, as I think stdio is mandatory in C++ and not many people try to
get light binaries using c++.
More information about the gmp-bugs