Namespaces
Variants
Views
Actions

Talk:cpp/types/integer

From cppreference.com
< Talk:cpp‎ | types
Revision as of 18:13, 19 January 2016 by Gubbins (Talk | contribs)

stdint.h is NOT C++11, but C99:

https://en.wikipedia.org/wiki/Stdint.h#stdint.h http://pwet.fr/man/linux/conventions/posix/stdint_h

In C, stdint.h first appears in the 1999 standard, yes. In C++, it first appears in the library extension TR1, which was merged into the mainline standard in C++11. --Cubbi 06:55, 22 November 2012 (PST)
stdint.h is definitely part of C++11. It's just deprecated in favour of cstdint. Rauy 08:10, 22 November 2012 (PST)


It seems the C99 standard also says that you must #define __STDC_FORMAT_MACROS before including inttypes.h in order for macros such as PRId64 to be defined. The same would therefore apply to C++ and cinttypes. I can't find any mention of that on here - is it an oversight? gubbins (talk) 18:23, 30 December 2015 (PST)

C99 says no such thing about C, but it makes this suggestion to C++. The C++ standard has wording that explicitly ignores this suggestion, in 27.9.2/3. C11 does not have the suggestion anymore. Interestingly, gcc had a bug in which it actually looked for that macro when in C++ mode. --Cubbi (talk) 20:59, 30 December 2015 (PST)
Wow, I am so confused. Thanks for the correction - I was building code on Linux with gcc 5.2.0 (-std=c++14) but still these macros were excluded - until I added __STDC_FORMAT_MACROS! I read a couple of things online which seemed to explain it but apparently I didn't read carefully enough (sigh) gubbins (talk) 20:15, 14 January 2016 (PST)
Oh you said gcc bug but you meant glibc bug right? gubbins (talk) 12:43, 19 January 2016 (PST)
yes, of course - as seen in the link above. --Cubbi (talk) 12:53, 19 January 2016 (PST)
and in fact that bug only covers __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS; I am still trying to figure out what my g++ / glibc combination is doing with __STDC_FORMAT_MACROS! gubbins (talk) 13:30, 19 January 2016 (PST)
OK, so in case anyone is interested... glibc applies the C99 suggestion, so gcc will #define __STDC_FORMAT_MACROS for you if you #include <cinttypes>, but if you #include <inttypes.h> first (or some library header does that for you as happened to me) then gcc doesn't (can't?) work around it and the format macros are missing. Seems to be fixed in glibc 2.18 although I can't find a bug report for that. I feel like it might be worth a side remark on the page since this confusion came about thanks to some text in the C99 standard, and is still affecting users now, so others might appreciate it... gubbins (talk) 18:13, 19 January 2016 (PST)