Nп/п : 45 из 100
 От   : Jeffrey R.Carter                    2:5075/128        23 сен 23 23:48:49
 К    : Maciej Sobczak                                        23 сен 23 00:51:07
 Тема : Re: Valid attribute and input operations
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> c6a0b202
@REPLY:
<22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com> 6c1d1bbc
@REPLYADDR Jeffrey R.Carter
<spam.jrcarter.not@spam.acm.org.not>
@REPLYTO 2:5075/128 Jeffrey R.Carter
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References:
<22930fd1-c7ff-46cf-8c75-892212afa85en@googlegroups.com>
@TZUTC: 0200
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:102.0)
Gecko/20100101 Thunderbird/102.15.1
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-09-23 22:22, Maciej Sobczak wrote:

 > I have checked the above program on several on-line compilers,
all of them behave according to interpretation 2 above.
> Richard claims to get behavior 1 on his compiler.

> What is your take on this? Any language lawyers?

The important thing is the definition of Ada.Text_IO.Integer_IO.Get [ARM 
A.10.8(7-10)]:

 "... skips any leading blanks, line terminators, or page terminators,
then reads 
 a plus sign if present or (for a signed type only) a minus sign
if present, then 
reads the longest possible sequence of characters matching the syntax of a 
numeric literal without a point. ...

"Returns, in the parameter Item, the value of type Num that corresponds to the 
sequence input.

"The exception Data_Error is propagated if the sequence of characters read does 
not form a legal integer literal or if the value obtained is not of the subtype 
Num."

So a call to Get can only return a valid value of type Num (Integer for your 
case) or raise Data_Error.

If Get is reading "500" then that certainly represents a valid value of type 
Integer, and Get should copy that back to the actual parameter.

If you are using Ada (a language with run-time checks), then a check should be 
made that the value is in the range of the actual parameter`s subtype, here 
Integer range 0 .. 200. That should fail and Constraint_Error should be raised.

However, if you are not using Ada because that check has been suppressed, then 
the actual parameter will be left with the invalid value 500 and 
Constraint_Error will not be raised.

If I build your program with checks enabled, I get Constraint_Error. If I build 
it with checks suppressed, I get the not-valid message (GNAT 12.3).

-- 
Jeff Carter
"If you don`t get the President of the United States on that
phone, ... you`re going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32

 --- Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх