Compiling with C++

Torbjörn Granlund tg at gmplib.org
Mon Nov 17 19:57:32 UTC 2014


Marc Glisse <marc.glisse at inria.fr> writes:

  If adding the usual:
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  ...
  
  #ifdef __cplusplus
  }
  #endif
  
  at the beginning / end of longlong.h works, that seems like a good
  solution. gmp.h and gmp-impl.h already have it.
  
It is true that gmp-impl.h has that.  But gmp.h is a bit more choosy
with its placement of these things.

Perhaps this would work:

diff -r 0f3ee27fb06b longlong.h
--- a/longlong.h	Sat Nov 15 20:46:48 2014 +0100
+++ b/longlong.h	Mon Nov 17 20:52:08 2014 +0100
@@ -1884,13 +1886,19 @@
 #endif
 
 
+#if defined (__cplusplus)
+#define __longlong_h_C "C"
+#else
+#define __longlong_h_C
+#endif
+
 /* Use mpn_umul_ppmm or mpn_udiv_qrnnd functions, if they exist.  The "_r"
    forms have "reversed" arguments, meaning the pointer is last, which
    sometimes allows better parameter passing, in particular on 64-bit
    hppa. */
 
 #define mpn_umul_ppmm  __MPN(umul_ppmm)
-extern UWtype mpn_umul_ppmm (UWtype *, UWtype, UWtype);
+extern __longlong_h_C UWtype mpn_umul_ppmm (UWtype *, UWtype, UWtype);
 
 #if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm  \
   && ! defined (LONGLONG_STANDALONE)
@@ -1903,7 +1911,7 @@
 #endif
 
 #define mpn_umul_ppmm_r  __MPN(umul_ppmm_r)
-extern UWtype mpn_umul_ppmm_r (UWtype, UWtype, UWtype *);
+extern __longlong_h_C UWtype mpn_umul_ppmm_r (UWtype, UWtype, UWtype *);
 
 #if ! defined (umul_ppmm) && HAVE_NATIVE_mpn_umul_ppmm_r	\
   && ! defined (LONGLONG_STANDALONE)
@@ -1916,7 +1924,7 @@
 #endif
 
 #define mpn_udiv_qrnnd  __MPN(udiv_qrnnd)
-extern UWtype mpn_udiv_qrnnd (UWtype *, UWtype, UWtype, UWtype);
+extern __longlong_h_C UWtype mpn_udiv_qrnnd (UWtype *, UWtype, UWtype, UWtype);
 
 #if ! defined (udiv_qrnnd) && HAVE_NATIVE_mpn_udiv_qrnnd	\
   && ! defined (LONGLONG_STANDALONE)


I am not actually super-fond of these mpn references in longlong.h.  I
would like to keep longlong.h non-specific to GMP.  A solution might be
to have a gmp-longlong.h wrapper with the stuff above, and always
include that instead of longlong.h directly, or grab longlong.h
unconditionally from gmp-impl.h (and the put the stuff above therein).

-- 
Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-discuss mailing list