Boost logo

Boost :

Subject: Re: [boost] boost/cstdint.hpp definition of INTMAX_C conflicts with MPFR
From: Vincent Lefevre (vincent_at_[hidden])
Date: 2010-02-16 05:44:03


On 2010-02-16 09:34:22 -0000, John Maddock wrote:
> No the problem with the next C++ std is *exactly* the same as with Boost:
>
> #include <cstdint> // perhaps indirectly via some other #include or
> std lib header.
> #include <mpfr.h> // error: no ::intmax_t even though INTMAX_C is
> defined (in practice may depend on the implementation - but this is
> what the std says should happen).
>
> Contrary to your expectations it is normal in C++ to include the C++
> headers such as <cstdint> and *not* the "legacy" C headers such as
> <stdint.h> to avoid polluting the global namespace.

OK, but in practice, that's a bit more complex: users may need legacy
C headers.

Note that MPFR is first a library written in C, for developers writing
their programs in C (there are also third-party interfaces to other
languages, though). Some conventional additions to mpfr.h have been
done to allow one to use <mpfr.h> in C++ software, but since MPFR
is for C primarily, this means that all the types are in the global
namespace. This may not be ideal, but some users accept this way of
doing (rather than using a MPFR C++ interface).

I've looked at the C++0x draft N3000 (November 2009), and <stdint.h>
is mentioned (Section 18.4.2); so, it is still part of the standard.
But even though Boost appears to work as if <cstdint> were included,
the <stdint.h> legacy C header is still unavailable on some platforms
(according to the bug report we got) if the user wants to include it
too, and I now think that's the main problem.

So, either you should tell your users that Boost may no longer be
compatible with legacy C headers and if they want to use C libraries,
they should use only pure C++ interfaces to them, or a way to use
legacy C headers should be documented. Perhaps a general rule should
be (I haven't tried): if the user needs to include legacy C headers,
he should always include them before C++ headers.

-- 
Vincent Lefèvre <vincent_at_[hidden]> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk