[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GMP C/C++ namespace conflict
From: |
Hans Aberg |
Subject: |
Re: GMP C/C++ namespace conflict |
Date: |
Wed, 25 Apr 2001 12:23:30 +0200 |
At 07:40 +1000 2001/04/25, Kevin Ryde wrote:
>> I got around this by defining:
>> #define free std::free
>> #define malloc std::malloc
>> #define realloc std::realloc
>
>gmp 3.1.1 uses <stdlib.h> to get the right prototypes, you might get
>more joy from it.
I have now switched to gmp 3.1.1.
But please note that under true C++ one would use <cstdlib> in order to not
get a "using namespace std" inserted into your code. Now, <stdlib.h> dote
seem to appear in any of the headers, so it makes no difference. But gmp.h
includes <stddef.h>, which under C++ should be replaced by <cstdlib>.
I can think of two ways around it. The first one is by having
#ifdef __cplusplus
#include <cstdlib>
#define std_(x) std::x
#else
#include <stdlib.h>
#define std_(x) /* empty */
#endif
and then write std_(size_t) instead of size_t. -- Perhaps too cumbersome.
The other way one might try is to have
#ifdef __cplusplus
#include <cstdlib>
#define size_t std::size_t /* For appropriate names */
#else
#include <stdlib.h>
#endif
and at the end of the file
#ifdef __cplusplus
#undef size_t std::size_t /* For the names previously macroed. */
#endif
Then the C code would look normal.
This is just an input; I do not know exactly how the stuff above will work
in practise.
Hans Aberg