bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C -> C++ bug in header file gmp.h


From: librik
Subject: C -> C++ bug in header file gmp.h
Date: Tue, 26 Feb 2002 20:00:42 -0500 (EST)

When the GMP 4.0.0 library is built with a C compiler, it can still
be linked with an application written in C++, because the header
file "gmp.h" includes the lines:
    #if defined (__cplusplus)
    extern "C" {
    #endif
and
    #if defined (__cplusplus)
    }
    #endif
wrapped around the declarations of functions.  This keeps the function
name from being mangled by the C++ compiler.  (The mangled names can't
be found, of course, in the C-compiled GMP shared library.)

Unfortunately, two names were accidentally omitted: the variables
    extern int __GMP_DECLSPEC gmp_errno;
    extern __gmp_const char * __gmp_const __GMP_DECLSPEC gmp_version;
As a result, it is impossible to use these two names from a C++
application when the GMP library was built as C.

Since both variables are declared __GMP_DECLSPEC, it is clear that
they were intended to be shared by the linking application.

The (fairly obvious) fix is to wrap extern "C" around the section
of gmp-h.in that declares these two variables.  See the following
patch.

- David Librik

*** gmp-h.in.orig       Thu Nov 29 07:55:30 2001
--- gmp-h.in    Tue Feb 26 18:54:50 2002
***************
*** 1989,1994 ****
--- 1989,1998 ----
  #define mpz_div_2exp  mpz_fdiv_q_2exp
  #define mpz_mod_2exp  mpz_fdiv_r_2exp

+ #if defined (__cplusplus)
+ extern "C" {
+ #endif
+
  #define gmp_errno __gmp_errno
  extern int __GMP_DECLSPEC gmp_errno;

***************
*** 2011,2016 ****
--- 2015,2024 ----

  #define gmp_version __gmp_version
  extern __gmp_const char * __gmp_const __GMP_DECLSPEC gmp_version;
+
+ #if defined (__cplusplus)
+ }
+ #endif

  #define __GMP_H__
  #endif /* __GMP_H__ */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]