In cplusplus.com reference for printf I see a specification for a "length" formatting, but it includes the note:
Yellow rows indicate specifiers and sub-specifiers introduced by C99. See
<cinttypes>
for the specifiers for extended types.
My question is specifically on the hh
length formatting. And it's a "yellow" row. Formatting with hh
behaves as expected in Visual Studio, but I'm wondering whether that's because Visual Studio is also C compiler or because hh
actually supported by C++?
The C++ standard used C90 as a normative reference until C++11 and so C99 features would only be supported in C++11. Although a compiler would be free to support them outside of C++11 as an extension. I would suspect this would only work with more recent versions of Visual Studio given their relatively recent drive to support C99 and cremno indicates that it is supported since 2015.
If we go to the C++11 draft standard section 1.2
Normative references [intro.refs] it says:
The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.
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 called the C standard library.1
prior to C++11 this was:
- ISO/IEC 9899:1990, Programming languages - C
and if we try an example in gcc using -std=c++03 -pedantic
it warns:
warning: ISO C++98 does not support the 'hh' gnu_printf length modifier [-Wformat=]
If you keep reading down the page
Those listed here are supported by the latest C and C++ standards (both published in 2011), but those in yellow were introduced in C99 (only required for C++ implementations since C++11)
So if you have Visual Studio 2013 or later, you will have access to (most) C++11 features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With