Nп/п : 48 из 100
 От   : Dmitry A. Kazakov                   2:5075/128        24 сен 23 09:50:48
 К    : Niklas Holsti                                         24 сен 23 10:54:03
 Тема : Re: Weird behavior of Get character with trailing new lines.
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> b567ac01
@REPLY: <kn89h2F64t4U1@mid.individual.net>
3a3ca148
@REPLYADDR Dmitry A. Kazakov
<mailbox@dmitry-kazakov.de>
@REPLYTO 2:5075/128 Dmitry A. Kazakov
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References: 1@dont-email.me>
1@dont-email.me> 1@dont-email.me> <kn7mhtF58psU1@mid.individual.net>
1@dont-email.me> <kn89h2F64t4U1@mid.individual.net>
@TZUTC: 0200
@PID: Mozilla Thunderbird
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-09-23 16:03, Niklas Holsti wrote:
> On 2023-09-23 12:25, Dmitry A. Kazakov wrote:

>> You exit the loop and do whatever is necessary there.

> That is exactly what happens in the "while not End_Of_File" loop.

It does not because you must handle I/O errors and close the file.

> If you want to use End_Error instead, you have to add an exception 
> handler, and if you want to stay in the subprogram`s statement sequence 
> without entering the subprogram-level exception handlers, you have to 
> add a block to contain the reading loop and make the exception handler 
> local to that block.

You always have to in order to handle I/O errors.

> To me that looks like adding code -> more complex. Of course not much 
> more complex, but a little, as I said.

No, it is simpler if the code is production code rather than an 
exercise. Consider typical case when looping implements reading some 
message, block etc. You have

    loop
       read something
       read another piece
       read some count
       read a block of count bytes
       ...

You cannot do it this way if you use end of file test because you must 
protect each minimal input item (e.g. byte) by the test. It is massively 
obtrusive and would distort program logic. You will end up with nested 
ifs or else gotos.

>> Testing for the file end is unreliable and non-portable. Many types
>> of files simply do not support that test.In other cases the test is
>> not file immutable with the side effects that can change the program
>> logic.

> I suppose you are talking about the need for End_Of_File to possibly 
> read ahead past a line terminator? If not, please clarify.

Yes, reading ahead and also issues with blocking and with race condition 
in shared files. Then things like sockets do not have end of file, 
connection drop is indicated by an empty read.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

--- Mozilla Thunderbird
 * 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    
                                                                                
В этой области больше нет сообщений.

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