Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > '5'-'0' = 5 alway? guaranteed?

Reply
Thread Tools

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

 
 
crea
Guest
Posts: n/a
 
      05-19-2011
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?


 
Reply With Quote
 
 
 
 
Alf P. Steinbach /Usenet
Guest
Posts: n/a
 
      05-19-2011
* 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>
 
Reply With Quote
 
 
 
 
crea
Guest
Posts: n/a
 
      05-19-2011

"Alf P. Steinbach /Usenet" <(E-Mail Removed)> wrote in
message news:ir3qlq$a84$(E-Mail Removed)...
>* 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.


 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      05-19-2011
On 5/19/2011 12:35 PM, crea wrote:
> "Alf P. Steinbach /Usenet"<(E-Mail Removed)> wrote in
> message news:ir3qlq$a84$(E-Mail Removed)...
>> * 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
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      05-19-2011
Noah Roberts <(E-Mail Removed)> 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)

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      05-19-2011
On 5/19/2011 3:58 PM, Noah Roberts wrote:
> On 5/19/2011 12:35 PM, crea wrote:
>> "Alf P. Steinbach /Usenet"<(E-Mail Removed)> wrote in
>> message news:ir3qlq$a84$(E-Mail Removed)...
>>> * 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
 
Reply With Quote
 
crea
Guest
Posts: n/a
 
      05-19-2011

"Pete Becker" <(E-Mail Removed)> 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.


 
Reply With Quote
 
Alf P. Steinbach /Usenet
Guest
Posts: n/a
 
      05-19-2011
* Stefan Ram, on 19.05.2011 22:09:
> Noah Roberts<(E-Mail Removed)> 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments