Email List: Xaustin-group-lX
[All Lists]

AI 2000-05-034: wording for strtod()

To: yyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: AI 2000-05-034: wording for strtod()
From: Ulrich Drepper <yyyyyyy@xxxxxxxxxx>
Date: 14 Aug 2000 13:01:40 -0700
Cc: Andrew Josey <yyyyyy@xxxxxxxxxxxxxxxxx>
The AI was actually to provide some extra words for the new strtod()
man page warning about the possible problems the adoption of ISO C99
brings.  Please find it attached below.  This should probably go into
app usage.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The changes to strtod() introduced by ISO C99 can alter the behavior
of well-formed programs complying with ISO C90 (and therefore SuSv2).
One such example would be this:

        int
        what_kind_of_number (char *s)
        {
          char *endp;
          double d;
          long l;

          d = strtod (s, &endp);
          if (s != endp && *endp == '\0')
            printf ("It's a float with value %g\n", d);
          else
            {
              l = strtol (s, &endp, 0);
              if (s != endp && *endp == '\0')
                printf ("It's an integer with value %ld\n", l);
              else
                return 1;
            }
          return 0;
        }

If the function is called with

        what_kind_of_number ("0x10")

an ISO C90 compliant library will result in the function printing

        It's an integer with value 16

With ISO C99 the result is

        It's a float with value 16


The problem is the addition of floating-point numbers in hexadecimal
notation without requiring that either a decimal point or the binary
exponent must be present.

<Prev in Thread] Current Thread [Next in Thread>