Boost C++ Libraries: Ticket #6852: lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format https://svn.boost.org/trac10/ticket/6852 <p> The following code produces a warning if compiled with GCC (4.7.0) and -Wall -std=c++98 -pedantic: </p> <pre class="wiki">include &lt;boost/lexical_cast.hpp&gt; int main() { boost::lexical_cast&lt;std::string&gt;(double(4.2)); return 0; } </pre><pre class="wiki">boost_1_49_0/include/boost/lexical_cast.hpp:1297:17: warning: ISO C++ does not support the ‘%lg’ gnu_printf format [-Wformat] </pre><p> With regard to the length modifier, the printf(3) man page (RHEL 6.2) states: </p> <pre class="wiki"> l (ell) A following integer conversion corresponds to a long int or unsigned long int argument, or a following n conversion cor- responds to a pointer to a long int argument, or a following c conversion corresponds to a wint_t argument, or a following s conversion corresponds to a pointer to wchar_t argument. </pre><p> With regard to the conversion specifier: </p> <pre class="wiki"> g, G The double argument is converted in style f or e (or F or E for G conversions). The precision specifies the number of signifi- cant digits. If the precision is missing, 6 digits are given; if the precision is zero, it is treated as 1. Style e is used if the exponent from its conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit. </pre><p> So the correct printf format for double is "%g". </p> <p> (Maybe this is different on non-GNU systems?) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6852 Trac 1.4.3 Antony Polukhin Wed, 02 May 2012 19:00:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6852#comment:1 https://svn.boost.org/trac10/ticket/6852#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/78308" title="Fixes #6852 (ISO C++ does not support the ‘%lg’ gnu_printf format fixed)">[78308]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6852" title="#6852: Bugs: lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format (closed: fixed)">#6852</a> (ISO C++ does not support the ‘%lg’ gnu_printf format fixed) </p> Ticket Antony Polukhin Thu, 10 May 2012 17:39:50 GMT <link>https://svn.boost.org/trac10/ticket/6852#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6852#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/78408" title="Fixes #6852 for wide characters (ISO C++ does not support the ‘%lg’ ...">[78408]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6852" title="#6852: Bugs: lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format (closed: fixed)">#6852</a> for wide characters (ISO C++ does not support the ‘%lg’ gnu_printf format fixed) </p> </description> <category>Ticket</category> </item> </channel> </rss>