Compiling a C program with g++ 4.3.1 yields an error about std::FILE
Marc Glisse
marc.glisse at normalesup.org
Thu Jul 24 16:19:34 CEST 2008
On Wed, 23 Jul 2008, Torbjorn Granlund wrote:
> Marc Glisse <marc.glisse at normalesup.org> writes:
>
> 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.
>
> I am preparing GMP 4.2.3, and if you have some safe C++ portability
> changes for that release, please sedn them to the list.
"safe": I am quite sure it is correct (whereas the current code isn't), it
helps with sunpro, and it does not break g++-4.3. I don't have much else
available here to test on...
The name freefunc_t is just an exemple, it would probably be better if it
was prefixed by gmp_ or something like that. The typedef could also be
moved to gmp.h as it seems like a useful addition to anyone who wants to
use mp_get_memory_functions, whether in C or C++, and in there it would
naturally fall inside a extern "C" when compiled in C++.
--- /usr/include/gmpxx.h 2008-04-09 08:42:55.000000000 +0200
+++ gmpxx.h 2008M G'-05-26 18:10:54.924190000 +0200
@@ -1291,13 +1291,15 @@
/* this is much the same as gmp_allocated_string in gmp-impl.h
since gmp-impl.h is not publicly available, I redefine it here
I use a different name to avoid possible clashes */
+
+extern "C" typedef void (*freefunc_t) (void *, size_t);
struct __gmp_alloc_cstring
{
char *str;
__gmp_alloc_cstring(char *s) { str = s; }
~__gmp_alloc_cstring()
{
- void (*freefunc) (void *, size_t);
+ freefunc_t freefunc;
mp_get_memory_functions (NULL, NULL, &freefunc);
(*freefunc) (str, std::strlen(str)+1);
}
Good luck with the next release,
--
Marc Glisse
More information about the gmp-bugs
mailing list