[cfe-dev] libcxx: Platform independent printing using format constants

Howard Hinnant hhinnant at apple.com
Thu Oct 11 10:56:36 PDT 2012


On Oct 11, 2012, at 12:35 AM, Richard Smith <richard at metafoo.co.uk> wrote:

> On Wed, Oct 10, 2012 at 9:34 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> libc++ does this to pick up the macro definitions:
> 
> #include <inttypes.h>
> 
> However, glibc's inttypes.h only provides them in C++ mode if _STDC_FORMAT_MACROS is defined, and libc++ doesn't define it.
> 
> Sorry, needs more underscore: __STDC_FORMAT_MACROS.

Right.  This is C++11-conforming.  27.9.2 [c.files]/p3:

> Table 135 describes header <cinttypes>. [ Note: The macros defined by <cinttypes> are provided unconditionally. In particular, the symbol __STDC_FORMAT_MACROS, mentioned in footnote 182 of the C standard, plays no role in C++. — end note ]

Summary:  <inttypes.h> should not be protecting anything in C++ based on __STDC_FORMAT_MACROS, despite the non-normative footnote in C99's 7.8.1.  When the C++ committee looked at this issue, they told the C committee "thanks but no thanks.".  See:

http://cplusplus.github.com/LWG/lwg-defects.html#593
http://cplusplus.github.com/LWG/lwg-defects.html#984

Howard


>  
> On Wed, Oct 10, 2012 at 12:53 PM, Daniel Hofmann <daniel at trvx.org> wrote:
> Hi,
> 
> I'm currently porting a program from g++/libstdc++ to clang/libcxx and
> was quite surprised that the platform independent printing using format
> constants, e.g. PRId64, produces errors with libcxx.
> 
> A simple example which compiles fine w/o libcxx or g++
> > #include <cstdio>
> > #include <cinttypes>
> >
> > int main() {
> >   int64_t n = 1;
> >
> >   printf("%" PRId64, n);
> > }
> 
> w/ -stdlib=libcxx
> > +7:14: error: expected ')'
> >   printf("%" PRId64, n);
> >              ^
> > +7:9: note: to match this '('
> >   printf("%" PRId64, n);
> >         ^
> 
> Although the cinttypes header comments lists them
> > Macros:
> >     ...
> >     PRId64
> 
> 
> So, what am I missing here? Is this not yet supported? How am I supposed
> to handle this?
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list