bug-gmp
[Top][All Lists]
Advanced

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

GMP C/C++ namespace conflict


From: Hans Aberg
Subject: GMP C/C++ namespace conflict
Date: Tue, 24 Apr 2001 11:23:10 +0200

[Followups, please cc me, as I am not on this list.]

When I used GMP as an inclusion in a program compiled under C++ (a
Flex/Bsion parser), I experienced conflicts between "name" and "std::name"
for the following names:
    free  malloc  realloc

I got around this by defining:
#define free std::free
#define malloc std::malloc
#define realloc std::realloc

The problem is caused by the lines in the gmp-impl.h header:

#if (__STDC__-0) || defined (__cplusplus)
void *malloc (size_t);
void *realloc (void *, size_t);
void free (void *);
...

If __cplusplus is defined, these names should be put in the namespace std:

#ifdef __cplusplus
namespace std {
#endif
void* malloc(size_t);
void* realloc(void*, size_t);
void free(void*);
#ifdef __cplusplus
} // namespace std
#endif


Also, in the gmp.h header, one might replace the line
  #include <stddef.h>
by:

#ifdef __cplusplus
#include <cstddef>
#else
#include <stddef.h>
#endif

However, names such as size_t will then no longer be in the global
namespace, so one might have to write something like:

#ifdef __cplusplus
#define std_(x) std::x
#else
#define std_(x)
#endif

and then write std_(size_t), etc.

  Hans Aberg





reply via email to

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