Discussion:
uint64_t fails with C++ (again)
Werner LEMBERG
2014-02-06 23:28:56 UTC
Permalink
In 2011, there was the following thread started by me:

http://lists.gnu.org/archive/html/autoconf/2011-12/msg00002.html

The solution that worked eventually was to put

AC_PROG_CC
AC_PROG_CPP

AC_TYPE_UINT64_T

into my configure.ac file, and

#include <config.h>

/* make `stdint.h' define `uintXX_t' for C++ */
#undef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS

#if HAVE_STDINT_H
# include <stdint.h>
#endif

#if defined UINT64_MAX || defined uint64_t
typedef uint64_t TA_ULongLong
#else
# error "No unsigned 64bit wide data type found."
#endif

into my C file.

However, this no longer works with g++ 4.7.2. As before, the test in
the `configure' script successfully gives

checking for uint64_t
g++ -c ... conftest.c >&5
configure:12694: $? = 0
configure:12694: result: yes

but neither `UINT64_MAX' nor `uint64_t' gets defined, causing

error: #error "No unsigned 64bit wide data type found."

during compilation.

If I have understood the issue correctly, `uint64_t' is no longer a
macro in the latest C++ standard, and UINT64_MAX isn't defined
either...

My solution was to add

if test x"$ac_cv_c_uint64_t" = x"yes"; then
AC_DEFINE([HAVE_UINT64_T], [1],
[Define if compiler accepts uint64_t data type.])
fi

to `configure.ac' (immediately after the call to `AC_TYPE_UINT64_T');
the new test in my C file is now

#if defined UINT64_MAX || defined uint64_t || defined HAVE_UINT64_T
typedef uint64_t TA_ULongLong;
...

Please comment. Is there a better solution?


Werner
Paul Eggert
2014-02-07 07:14:36 UTC
Permalink
Post by Werner LEMBERG
neither `UINT64_MAX' nor `uint64_t' gets define
That's odd, because UINT64_MAX is defined for me, even for this
much-simpler program:

#include <stdint.h>
#ifdef UINT64_MAX
typedef uint64_t TA_ULongLong;
#else
# error "No unsigned 64bit wide data type found."
#endif

If I put this into a file "t.cc", the command "g++ -c t.cc" works just
fine. I'm using Fedora 20, which has g++ (GCC) 4.8.2 20131212 (Red Hat
4.8.2-7).

Maybe you didn't define HAVE_STDINT_H?
Werner LEMBERG
2014-02-07 07:24:09 UTC
Permalink
Hello Paul!
Post by Paul Eggert
Post by Werner LEMBERG
neither `UINT64_MAX' nor `uint64_t' gets define
That's odd, because UINT64_MAX is defined for me, even for this
#include <stdint.h>
#ifdef UINT64_MAX
typedef uint64_t TA_ULongLong;
#else
# error "No unsigned 64bit wide data type found."
#endif
If I put this into a file "t.cc", the command "g++ -c t.cc" works just
fine. I'm using Fedora 20, which has g++ (GCC) 4.8.2 20131212 (Red
Hat 4.8.2-7).
Repeating your test verbatim I get the #error message! This is

g++ (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012]
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

So maybe I'm hitting a bug in the 4.7 series of gcc that has been
fixed meanwhile?
Post by Paul Eggert
Maybe you didn't define HAVE_STDINT_H?
HAVE_STDINT_H is defined as 1 in `config.h'.


Werner
Paul Eggert
2014-02-07 08:19:31 UTC
Permalink
Post by Werner LEMBERG
Repeating your test verbatim I get the #error message!
I'm not too surprised, since you're probably using a pre-C++11 system.
I get the same #error on RHEL 6.4, which uses g++ (GCC) 4.4.7 20120313
(Red Hat 4.4.7-3), which is older even than your compiler. How about if
you compile with the following command instead?

g++ -D__STDC_LIMIT_MACROS -c t.cc

That fixes the problem on RHEL 6.4, anyway.
Werner LEMBERG
2014-02-07 08:34:42 UTC
Permalink
Post by Werner LEMBERG
Repeating your test verbatim I get the #error message!
How about if you compile with the following command instead?
g++ -D__STDC_LIMIT_MACROS -c t.cc
That fixes the problem on RHEL 6.4, anyway.
It works for me, too.

Will this problem be handled in a forthcoming autoconf release?


Werner
Paul Eggert
2014-02-07 08:45:21 UTC
Permalink
Post by Werner LEMBERG
Will this problem be handled in a forthcoming autoconf release?
I'm afraid I don't understand the problem yet, as your original email
defined __STDC_LIMIT_MACROS, but now you're saying that
-D__STDC_LIMIT_MACROS fixes the problem. That being said, my guess is
that it's not an autoconf bug.

I tend to work around these sorts of glitches using Gnulib; its stdint
module fixes the portability problem with __STDC_LIMIT_MACROS that I
know about. Admittedly Gnulib is not for everybody.
Werner LEMBERG
2014-02-07 09:46:03 UTC
Permalink
Post by Paul Eggert
Post by Werner LEMBERG
Will this problem be handled in a forthcoming autoconf release?
I'm afraid I don't understand the problem yet, as your original
email defined __STDC_LIMIT_MACROS, but now you're saying that
-D__STDC_LIMIT_MACROS fixes the problem.
Indeed, doing

./configure CC=g++ CPPFLAGS="-D__STDC_LIMIT_MACROS"

fixes the issue, too.
Post by Paul Eggert
That being said, my guess is that it's not an autoconf bug.
Yep, it's a gcc bug. Attached you can find some tests; hopefully,
this helps you.
Post by Paul Eggert
I tend to work around these sorts of glitches using Gnulib; its
stdint module fixes the portability problem with __STDC_LIMIT_MACROS
that I know about. Admittedly Gnulib is not for everybody.
Hehe. I use gnulib, so this is just fine for me.


Werner
Werner LEMBERG
2014-02-07 09:50:20 UTC
Permalink
Post by Werner LEMBERG
Post by Paul Eggert
I tend to work around these sorts of glitches using Gnulib; its
stdint module fixes the portability problem with
__STDC_LIMIT_MACROS that I know about. Admittedly Gnulib is not
for everybody.
Hehe. I use gnulib, so this is just fine for me.
Will test `stdint' module soon – I've never thought of using this with
gcc itself...


Werner
Werner LEMBERG
2014-02-15 07:24:13 UTC
Permalink
Post by Werner LEMBERG
Post by Werner LEMBERG
Post by Paul Eggert
I tend to work around these sorts of glitches using Gnulib; its
stdint module fixes the portability problem with
__STDC_LIMIT_MACROS that I know about. Admittedly Gnulib is not
for everybody.
Hehe. I use gnulib, so this is just fine for me.
Will test `stdint' module soon – I've never thought of using this with
gcc itself...
For completeness: gnulib's `stdint' module works just fine.


Werner

Loading...