C ++ Support for length specifiers

In the cplusplus.com link for printf I see the formatting specification "length", but it includes a note:

Yellow lines indicate the specifiers and subindicators entered by C99. See <cinttypes> for specifiers for extended types.

My question is specifically about hh length formatting. And this is the yellow row. Formatting with hh behaves as expected in Visual Studio, but I wonder because Visual Studio is also a C compiler, or because hh actually supported by C ++?

+7
c ++ c char formatting printf
source share
2 answers

The C ++ standard used C90 as a normative reference until C ++ 11, so C99 functions were only supported in C ++ 11. Although the compiler could freely support them outside of C ++ 11 as an extension. I would suggest that this would only work with later versions of Visual Studio , given their relatively recent C99 support disk, and cremno indicates that it has been supported since 2015 .

If we move on to the standard section of the C ++ 11 project 1.2 Normative references [intro.refs], he says:

The following referenced documents are required to apply this document. For dated references, only the edition cited. For undated references, latest edition (including any amendments).

and includes:

  • ISO / IEC 9899: 1999, Programming Languages ​​- C

and also says:

The library described in clause 7 of ISO / IEC 9899: 1999 and clause 7 of ISO / IEC 9899: 1999 / Cor.1: 2001 and clause 7 of ISO / IEC 9899: 1999 / Cor.2: 2003 is hereinafter referred to as the standard C library. one

before C ++ 11 it was:

  • ISO / IEC 9899: 1990, Programming Languages ​​- C

and if we try the example in gcc using -std=c++03 -pedantic , it warns:

warning: ISO C ++ 98 does not support the length modifier hh 'gnu_printf [-Wformat =]

+5
source share

If you keep reading the page

The ones listed here are supported by the latest C and C ++ standards (both published in 2011), but those that were in yellow were introduced in C99 (only required for C ++ implementations with C ++ 11 )

So, if you have Visual Studio 2013 or later, you will have access to most of the features of C ++ 11.

+3
source share

All Articles