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

Marc Glisse marc.glisse at
Fri Jul 25 14:37:18 CEST 2008

On Thu, 24 Jul 2008, Torbjorn Granlund wrote:

>  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++.
> I'll leave it in gmpxx.h for this dot-release.
> Why have the freefunc_t globally in gmpxx.h, why not put it into the
> function, to avoid namespace pollution?

That indeed would be nice, but it is forbidden to have linkage 
specifications inside anything. (It was the first thing I tried :-)

> A related isue with gmpxx.h: We use many short, non-prefixed variable names like
> "s", and "f" and "z" in gmpxx.h.  If a user decides to say
>   #define s )
> before includng gmpxx.h, I think gmpxx.h will not work too well.  In
> C, one typically uses prefixes to avoid this.  Shouldn't this be done
> for gmpxx.h also?

I know libstdc++ uglifies all variable names, but only compiler 
implementors have this luxury (using __gmp* in gmp is already forbidden 
and generates warnings with some compilers).

I think mostly in C++ you can consider it the user's fault if they #define 
short variables, although we recently had problems with solaris defining 
plenty of macros with just two capital letters.

If noone complains, I wouldn't worry about this.

> It turns out that gcc 2.95 has problems with the new code.  Yes, some
> of my test machines still use that old compiler.  :-)

I actually still have 2.72, 2.95, 3.3, 3.4, 4.0, 4.1, 4.2 and 4.3 on an 
other machine for test purposes so I can verify this.

> The error is:
>  gmpxx.h:1349: multiple storage classes in declaration of `__gmp_freefunc_t'
> At line 1349, we have this new line:
>  extern "C" typedef void (*__gmp_freefunc_t) (void *, size_t);
> I'd like to make the code work with 2.95, if possible.
> What would a correct alternatve form for older c++ compilers be?  Just
> dropping the 'extern "C"' seems to help with this particular gcc
> release.

The whole point of using a typedef is so we can have the extern "C"...

modifying it to:
extern "C" {
   typedef ...;

seems to help at compile time, but then the linker gives funny messages.

/usr/bin/ld: error in t-misc.o(.eh_frame); no .eh_frame_hdr table will be 

However, I think I already have this without the patch, so g++-2.95 might 
simply not work anymore on this system. Can you try the version with { and 
} on your system?

Marc Glisse

More information about the gmp-bugs mailing list