While compiling programs on Linux 32-bit with Comeau C/C++ 4.3.10.1 front-end and GCC 4.3.3 I encountered some problems using Boost Integer library, namely boost/cstdint.hpp header. Here we go:
If I first include sys/types.h (added with POSIX), directly or indirectly, and then include boost/cstdint.hpp in C++ program:
#include <sys/types.h>
#include <boost/cstdint.hpp>
int main()
{
boost::int64_t a(0);
}
then it does not compile:
$ como -I/home/mloskot/dev/boost/_svn/trunk test1.cpp
MODE:non-strict warnings C++ noC++0x_extensions
"/home/mloskot/dev/boost/_svn/trunk/boost/cstdint.hpp", line 111: error: the
global scope has no "int64_t"
using ::int64_t;
^
"bad.cpp", line 5: error: namespace "boost" has no member "int64_t"
boost::int64_t a(0);
^
Then, if stdint.h (added with C99) is included first (again, directly or indirectly), then the program compiles without any errors:
#include <stdint.h>
#include <boost/cstdint.hpp>
int main()
{
boost::int64_t a(0);
}
It turns out that there is some amount of overlap in the stdint.h and sys/types.h headers. The issue is that the overlapped parts slightly differ. For the architecture, operating system and compilation toolset I use, both headers define int64_t type as follows:
typedef long long int int64_t;
However, the definition in sys/types.h header is guarded with different preprocessor condition testing __GLIBC_HAVE_LONG_LONG:
# elif __GLIBC_HAVE_LONG_LONG
__extension__ typedef long long int int64_t;
# endif
If I change sys/types.h replacing the clause with simple #else:
# else
__extension__ typedef long long int int64_t;
# endif
then the first variant of my program, the one including sys/types.h, does compile perfectly well.
Now, is this small difference a bug in the GNU C Library?
I’m going to try to confirm it.