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

C

crea

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?
 
A

Alf P. Steinbach /Usenet

* 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
 
C

crea

Alf P. Steinbach /Usenet said:
* crea, on 19.05.2011 21:13:

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.
 
S

Stefan Ram

Noah Roberts said:
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)
 
C

crea

Pete Becker said:
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.
 
A

Alf P. Steinbach /Usenet

* Stefan Ram, on 19.05.2011 22:09:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top