'5'-'0' = 5 alway? guaranteed?

Discussion in 'C++' started by crea, May 19, 2011.

  1. crea

    crea Guest

    I am just programming this kind of thing, and was wondering I according to
    c++ language it is always guaranteed that
    '5'-'0' = 5. Character calculations. Because character should be in order
    isnt it? Is it guaranteed that they are in order and the difference is 1?
    crea, May 19, 2011
    #1
    1. Advertising

  2. * crea, on 19.05.2011 21:13:
    > I am just programming this kind of thing, and was wondering I according to
    > c++ language it is always guaranteed that
    > '5'-'0' = 5. Character calculations. Because character should be in order
    > isnt it? Is it guaranteed that they are in order and the difference is 1?


    Yes.

    But that does not hold for letters (which are discontiguous in EBCDIC, which the
    C++ standard "must" support).


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, May 19, 2011
    #2
    1. Advertising

  3. crea

    crea Guest

    "Alf P. Steinbach /Usenet" <> wrote in
    message news:ir3qlq$a84$...
    >* crea, on 19.05.2011 21:13:
    >> I am just programming this kind of thing, and was wondering I according
    >> to
    >> c++ language it is always guaranteed that
    >> '5'-'0' = 5. Character calculations. Because character should be in order
    >> isnt it? Is it guaranteed that they are in order and the difference is 1?

    >
    > Yes.
    >
    > But that does not hold for letters (which are discontiguous in EBCDIC,
    > which the C++ standard "must" support).
    >


    ok, good to know also the letter-thing.
    crea, May 19, 2011
    #3
  4. crea

    Noah Roberts Guest

    On 5/19/2011 12:35 PM, crea wrote:
    > "Alf P. Steinbach /Usenet"<> wrote in
    > message news:ir3qlq$a84$...
    >> * crea, on 19.05.2011 21:13:
    >>> I am just programming this kind of thing, and was wondering I according
    >>> to
    >>> c++ language it is always guaranteed that
    >>> '5'-'0' = 5. Character calculations. Because character should be in order
    >>> isnt it? Is it guaranteed that they are in order and the difference is 1?

    >>
    >> Yes.
    >>
    >> But that does not hold for letters (which are discontiguous in EBCDIC,
    >> which the C++ standard "must" support).
    >>

    >
    > ok, good to know also the letter-thing.
    >
    >


    He's wrong actually. It's a really good bet, but by no means guaranteed.

    --
    http://crazycpp.wordpress.com
    Noah Roberts, May 19, 2011
    #4
  5. crea

    Stefan Ram Guest

    Noah Roberts <> writes:
    >He's wrong actually. It's a really good bet, but by no means guaranteed.


    Then how for any digit character c, the expression
    (do_narrow(c,dfault)-'0') evaluates to the digit value of
    the character? (according to ISO/IEC 14882:2003(E)
    22.2.1.1.2 char do_narrow(charT c, char dfault) const,
    Effects)
    Stefan Ram, May 19, 2011
    #5
  6. On 5/19/2011 3:58 PM, Noah Roberts wrote:
    > On 5/19/2011 12:35 PM, crea wrote:
    >> "Alf P. Steinbach /Usenet"<> wrote in
    >> message news:ir3qlq$a84$...
    >>> * crea, on 19.05.2011 21:13:
    >>>> I am just programming this kind of thing, and was wondering I according
    >>>> to
    >>>> c++ language it is always guaranteed that
    >>>> '5'-'0' = 5. Character calculations. Because character should be in
    >>>> order
    >>>> isnt it? Is it guaranteed that they are in order and the difference
    >>>> is 1?
    >>>
    >>> Yes.
    >>>
    >>> But that does not hold for letters (which are discontiguous in EBCDIC,
    >>> which the C++ standard "must" support).
    >>>

    >>
    >> ok, good to know also the letter-thing.
    >>
    >>

    >
    > He's wrong actually. It's a really good bet, but by no means guaranteed.


    No, he is not. Read [lex.charset]/3. Carefully.

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, May 19, 2011
    #6
  7. crea

    crea Guest

    "Pete Becker" <> wrote in message
    news:2011051916213466006-pete@versatilecodingcom...
    > On 2011-05-19 15:58:29 -0400, Noah Roberts said:
    >>>
    >>> ok, good to know also the letter-thing.
    >>>
    >>>

    >>
    >> He's wrong actually. It's a really good bet, but by no means guaranteed.

    >
    > The character representations of the digits 0-9 are required to be
    > contiguous and in ascending order. And there's no similar requirement for
    > any other characters.
    >


    Thanks guys, good info which would be difficult to find from books (well,
    maybe google would help but this is not something which is told in schools
    or books) - yes, they use it sometimes, but I never read that its
    "guaranteed to work" which I really need to know.
    crea, May 19, 2011
    #7
  8. * Stefan Ram, on 19.05.2011 22:09:
    > Noah Roberts<> writes:
    >> He's wrong actually. It's a really good bet, but by no means guaranteed.

    >
    > Then how for any digit character c, the expression
    > (do_narrow(c,dfault)-'0') evaluates to the digit value of
    > the character? (according to ISO/IEC 14882:2003(E)
    > 22.2.1.1.2 char do_narrow(charT c, char dfault) const,
    > Effects)


    Noah is in my killfile so I don't see his article. And he knows that. And
    needless to say, Noah's public insinuation that I was guessing, knowing full
    well that I don't see his article, is just what one can expect from him.

    If you want to check out the formal it's at the very start of the standard
    somewhere .

    You can download the latest draft (of the next standard) from the committee pages.


    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
    Alf P. Steinbach /Usenet, May 19, 2011
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mick

    $5 INSTANT PAYMENTS GUARANTEED

    mick, Jan 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    396
  2. Ben Fidge
    Replies:
    2
    Views:
    715
    Juan T. Llibre
    Sep 7, 2005
  3. Razvan
    Replies:
    5
    Views:
    4,449
    Razvan
    Sep 9, 2004
  4. chak
    Replies:
    2
    Views:
    983
  5. Ne7ven
    Replies:
    0
    Views:
    1,697
    Ne7ven
    Apr 18, 2011
Loading...

Share This Page