Modify

Ticket #6852 (closed Bugs: fixed)

Opened 2 years ago

Last modified 2 years ago

lexical_cast: warning: ISO C++ does not support the ‘%lg’ gnu_printf format

Reported by: peter@… Owned by: apolukhin
Milestone: To Be Determined Component: lexical_cast
Version: Boost 1.49.0 Severity: Cosmetic
Keywords: Cc:

Description

The following code produces a warning if compiled with GCC (4.7.0) and -Wall -std=c++98 -pedantic:

include <boost/lexical_cast.hpp>

int main()
{
    boost::lexical_cast<std::string>(double(4.2));
    return 0;
}
boost_1_49_0/include/boost/lexical_cast.hpp:1297:17: warning: ISO C++ does not support the ‘%lg’ gnu_printf format [-Wformat]

With regard to the length modifier, the printf(3) man page (RHEL 6.2) states:

       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.

With regard to the conversion specifier:

       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.

So the correct printf format for double is "%g".

(Maybe this is different on non-GNU systems?)

Attachments

Change History

comment:1 Changed 2 years ago by apolukhin

  • Status changed from new to closed
  • Resolution set to fixed

(In [78308]) Fixes #6852 (ISO C++ does not support the ‘%lg’ gnu_printf format fixed)

comment:2 Changed 2 years ago by apolukhin

(In [78408]) Fixes #6852 for wide characters (ISO C++ does not support the ‘%lg’ gnu_printf format fixed)

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.