data type for decimal number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ymuntyan@gmail.com

    #16
    Re: data type for decimal number

    On Feb 18, 12:32 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
    wrote:
    In article <7J-dnX6UeKWCWiTanZ 2dnUVZ8sDin...@ bt.com>,
    Richard Heathfield <r...@see.sig.i nvalidwrote:
    >
    >
    >
    Harald van D?k said:
    On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
    >Keith Thompson said:
    >>Richard Heathfield <r...@see.sig.i nvalidwrites:
    >>>Actually, %x takes an int, not a hex. C doesn't have a hex type.
    >>Actually, %x takes an unsigned int.
    >4.9.6.1 of C89:
    >d, i, o, u, x, X The int argument is converted to signed decimal ( d
    > or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
    > hexadecimal notation ( x or X );
    >Sure looks like int to me.
    Interesting. C99 7.19.6.1p8:
    o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
    unsigned decimal (u), or unsigned hexadecimal notation (x or X)
    in the style /dddd/; [...]
    Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
    - and a potentially significant one, since it causes difficulty for those
    wishing to program in the common subset of the two languages. I say
    "perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
    as such is suspect in cases like this. Does anyone have a kosher copy of
    the "real" C89 in which they could check this out?
    >
    I have the official ANSI C89 hard-copy publication. It describes
    the integer formats in two related paragraphs, the first of which
    is a summary for all of the formats and uses "int", and the second
    of which is specific to o,u,x,X and uses "unsigned int".
    So this means that the ISO standard was actually different from
    the ANSI one (because the ISO one has two paragraphs, one for 'i,d',
    and another one for 'o,u,x,X')? Is there a list of changes somewhere?

    Yevgen

    Comment

    • Richard Heathfield

      #17
      Re: data type for decimal number

      Walter Roberson said:

      <snip>
      I have the official ANSI C89 hard-copy publication. It describes
      the integer formats in two related paragraphs, the first of which
      is a summary for all of the formats and uses "int", and the second
      of which is specific to o,u,x,X and uses "unsigned int".
      >
      I consider the second of the paragraphs to be a refinement of the first,
      with the first giving the overview and the second the specifics. Thus
      I see no contradiction between versions: as far as I am concerned, both
      C89 and C99 specify that %x and %X require unsigned int.
      Thank you, Walter. I have amended my C89 draft accordingly (because
      otherwise I'll only make the same stupid mistake again!).

      And, of course, my apologies to all, for posting misleading information
      upthread.

      --
      Richard Heathfield <http://www.cpax.org.uk >
      Email: -http://www. +rjh@
      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
      "Usenet is a strange place" - dmr 29 July 1999

      Comment

      • lawrence.jones@siemens.com

        #18
        Re: data type for decimal number

        Walter Roberson <roberson@ibd.n rc-cnrc.gc.cawrote :
        >
        I have the official ANSI C89 hard-copy publication. It describes
        the integer formats in two related paragraphs, the first of which
        is a summary for all of the formats and uses "int", and the second
        of which is specific to o,u,x,X and uses "unsigned int".
        That's interesting, *my* nearly-official copy (what was sent to ANSI for
        publication) matches ANSI/ISO C90: the first paragraph is for "d" and
        "i" and says "int", the second paragraph is for "o", "u", "x", and "X"
        and says "unsigned int". Are you sure you're not misreading it? I
        sincerely doubt that ANSI change the camera-ready copy.

        -Larry Jones

        You know how Einstein got bad grades as a kid? Well MINE are even WORSE!
        -- Calvin

        Comment

        • Keith Thompson

          #19
          Re: data type for decimal number

          Mark Bluemel <mark_bluemel@p obox.comwrites:
          Keith Thompson wrote:
          >
          >... unsigned long is very
          >often the same size as unsigned long, but it's not guaranteed.
          >
          Is this the Schroedinger C compiler we're talking about here?
          Yes and no.

          What I meant is that unsigned long is very often the same size as void*.

          --
          Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
          Nokia
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • Keith Thompson

            #20
            Re: data type for decimal number

            roberson@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
            In article <7J-dnX6UeKWCWiTanZ 2dnUVZ8sDinZ2d@ bt.com>,
            Richard Heathfield <rjh@see.sig.in validwrote:
            >>Harald van D?k said:
            >
            >>On Mon, 18 Feb 2008 17:22:37 +0000, Richard Heathfield wrote:
            >>>Keith Thompson said:
            >>>>Richard Heathfield <rjh@see.sig.in validwrites:
            >>>>>Actually , %x takes an int, not a hex. C doesn't have a hex type.
            >
            >>>>Actually, %x takes an unsigned int.
            >
            >>>4.9.6.1 of C89:
            >
            >>>d, i, o, u, x, X The int argument is converted to signed decimal ( d
            >>> or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
            >>> hexadecimal notation ( x or X );
            >
            >>>Sure looks like int to me.
            >
            >>Interesting . C99 7.19.6.1p8:
            >
            >>o,u,x,X The _unsigned int_ argument is converted to unsigned octal (o),
            >> unsigned decimal (u), or unsigned hexadecimal notation (x or X)
            >> in the style /dddd/; [...]
            >
            >>Hmmm. Okay, so that's (perhaps) Yet Another Difference between C89 and C99
            >>- and a potentially significant one, since it causes difficulty for those
            >>wishing to program in the common subset of the two languages. I say
            >>"perhaps" because my source doc for C89 is (pace, C.H.!) a mere draft, and
            >>as such is suspect in cases like this. Does anyone have a kosher copy of
            >>the "real" C89 in which they could check this out?
            >
            I have the official ANSI C89 hard-copy publication. It describes
            the integer formats in two related paragraphs, the first of which
            is a summary for all of the formats and uses "int", and the second
            of which is specific to o,u,x,X and uses "unsigned int".
            >
            I consider the second of the paragraphs to be a refinement of the first,
            with the first giving the overview and the second the specifics. Thus
            I see no contradiction between versions: as far as I am concerned, both
            C89 and C99 specify that %x and %X require unsigned int.
            I have the official ISO C90 PDF publication. Here's what it says:

            d,i The int argument is converted to signed decimal in the style
            (-]dddd. The precision specifies the minimum number of digits
            to appear, if the value being converted can be represented in
            fewer digits, it will be expanded with leading zeros. The
            default precision is 1. The result of converting a zero value
            with a precision of zero is no characters.

            o,u,x,X The unsigned int argument is converted to unsigned octal (o),
            unsigned decimal (u), or unsigned hexadecimal notation (x or
            X) in the style dddd, the letters abcdef are used for x
            conversion and the letters ABCDEF for X conversion. The
            precision specifies the minimum number of digits to appear; if
            the value being converted can be represented in fewer digits,
            it will be expanded with leading zeros. The default precision
            is 1. The result of converting a zero value with a precision
            of zero is no characters.

            (It's not a good PDF copy; there may be typos in the above.)

            Does that not match the ANSI C89 standard?

            --
            Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
            Nokia
            "We must do something. This is something. Therefore, we must do this."
            -- Antony Jay and Jonathan Lynn, "Yes Minister"

            Comment

            • Martin

              #21
              Re: data type for decimal number

              On Feb 18, 6:42 pm, Ben Pfaff <b...@cs.stanfo rd.eduwrote:
              This was corrected in the corresponding paragraph of
              the C99 rationale: [...]
              This is all rather unfortunate. K&R2, Plauger, http://flash-gordon.me.uk/ansi.c.txt
              and http://www.lysator.liu.se/c/rat/d9.html#4-9-6-1 all say int is
              used for o, u, x, X, yet the definitive resource (ISO/IEC 9899:1990)
              says they expect unsigned int, and it's a resource I can't get hold of
              - I have to rely on quotes on this Newsgroup.

              I have the C99 Standard, but my compiler doesn't support it.

              --
              Martin

              Comment

              • Walter Roberson

                #22
                Re: data type for decimal number

                In article <wOqdnVSk2JVsIC TaRVnyggA@bt.co m>,
                Richard Heathfield <rjh@see.sig.in validwrote:
                >4.9.6.1 of C89:
                >
                >d, i, o, u, x, X The int argument is converted to signed decimal ( d
                or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
                hexadecimal notation ( x or X );
                >Sure looks like int to me.
                Extracting the relevant paragraphs of C89 4.9.6.1, starting from
                page 133 of the hardcopy (X3.159-1989)

                ==== page 133 ====

                o An option precision gives the minimum number of digits to appear
                for the d, i, o, u, x, and X conversions, the number of digits
                to appear after the decimal-point character for e, E, and f
                conversions, the maximum number of significant digits for the
                g and G conversions, or the maximum number of characters to
                be written from a string in s conversion. The precision takes
                the form of a period (.) followed either by an asterisk *
                (described later) or by an option decimal integer; if only the
                period is specified, the precision is taken as zero. If the
                precision appears with any other conversion specifier, the
                behavior is undefined.

                o An optional h specifiing that the following d, i, o, u, x, or X
                conversion specifier applies to a short int or unsigned short int
                argument (the argument will have been promoted according
                to the integral promotions, and its value shall be converted to
                short int or unsigned short int before printing); an optional h
                specifying that a following n conversion specifier applies to
                a pointer to a short in argument; an optional l (ell)
                specifying that the following d, i, o, u, x, or X conversion
                specifier applies to a long int or unsigned long int argument;
                an optional l specifying that a following n conversion specifier
                applies to a poiner to a long int argument; or an optional L
                specifying that a following e, E, f, g, or G conversion specifier
                applies to a long double argument. If an h, l or L appears
                with any other conversion specifier, the behavior is undefined.
                [...]
                The flag characters and their meanings are
                [...]
                # The result is to be converted to an "alternate form". For o
                conversions, it increases the precision to force the first digit
                of the result to be a zero. For x (or X) conversion, a
                nonzero result with have 0x (or 0X) prefixed to it. For
                e, E, f, g, and G conversion, the result will always contain
                a decimal-point character, even if no digits follow it.
                (Normally, a decimal-point character appears in the result of
                these conversions only if a digit follows it.) For g and G
                conversions, trailing zeros will not be removed from the
                result. For other conversions, the behavior is undefined.

                ==== page 134 ====
                0 For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros
                (following any indication of sign or base) are used to pad to
                the field width; no space padding is performed. If the 0 and -
                flags both appear, the 0 flag will be ignored. For d, i, o, u,
                x, and X conversions, if a precision is specified, the 0 flag
                will be ignored. For other conversions, the behavior is undefined.

                The conversion specifiers and their meanings are

                d,i The int argument is converted to signed decimal in the style
                [-]dddd. The precision specifies the minimum number of digits
                to appear; if the value being converted can be represented in
                fewer digits, it will be expanding with leading zeros. The
                default precision is 1. The result of converting a zero value with
                a precision of zero is no characters.

                o,u,x,X The unsigned int argument is converted to unsigned octal (o),
                unsigned decimal (u), or unsigned hexadecimal notation (x or X)
                in the style dddd; the letters abcdef are used for x conversion
                and the letters ABCDEF for X conversion. The precision specifies
                the minimum number of digits to appear; if the value being
                converted can be represented in fewer digits, it will be expanded
                with leading zeros. The default precision is 1. The result of
                converting a zero value with a precision of zero is no characters.

                c The int argument is converted to an unsigned char, and the
                resulting character is written.


                ====
                The text quoted by Richard Heathfield does NOT appear in
                C89 4.9.6.1 in the hardcopy version. (I do not know what his source
                was.)
                --
                "When a scientist is ahead of his times, it is often through
                misunderstandin g of current, rather than intuition of future truth.
                In science there is never any error so gross that it won't one day,
                from some perspective, appear prophetic." -- Jean Rostand

                Comment

                • Richard Heathfield

                  #23
                  Re: data type for decimal number

                  Walter Roberson said:
                  In article <wOqdnVSk2JVsIC TaRVnyggA@bt.co m>,
                  Richard Heathfield <rjh@see.sig.in validwrote:
                  >
                  >>4.9.6.1 of C89:
                  >>
                  >>d, i, o, u, x, X The int argument is converted to signed decimal ( d
                  > or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
                  > hexadecimal notation ( x or X );
                  >
                  >>Sure looks like int to me.
                  >
                  Extracting the relevant paragraphs of C89 4.9.6.1, starting from
                  page 133 of the hardcopy (X3.159-1989)
                  Er, Walter, this is weeks old, if not months.
                  ====
                  The text quoted by Richard Heathfield does NOT appear in
                  C89 4.9.6.1 in the hardcopy version.
                  So I understand.
                  (I do not know what his source was.)
                  A draft copy of C89. (I have a "real" C99 Standard, but not C89.)

                  --
                  Richard Heathfield <http://www.cpax.org.uk >
                  Email: -http://www. +rjh@
                  Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                  "Usenet is a strange place" - dmr 29 July 1999

                  Comment

                  • Walter Roberson

                    #24
                    Re: data type for decimal number

                    In article <6dSdnQ_iDerGQF PanZ2dnUVZ8vCdn Z2d@bt.com>,
                    Richard Heathfield <rjh@see.sig.in validwrote:
                    >Walter Roberson said:
                    >Extracting the relevant paragraphs of C89 4.9.6.1, starting from
                    >page 133 of the hardcopy (X3.159-1989)
                    >Er, Walter, this is weeks old, if not months.
                    February 18th actually. But someone responded today (or last night)
                    in the thread, and when I went back up the chain I could see there
                    was still confusion about where exactly the unsigned had appeared,
                    with the follow-up postings appearing to indicate that the change
                    appeared in the Rationale for C99, whereas they were in C89 to start with.
                    So I quoted everything relevant to (hopefully) settle the matter.
                    --
                    "The beauties of conception are always superior to those of
                    expression." -- Walter J. Phillips

                    Comment

                    Working...