Understanding {$I-} {$I+} ioResult

Baudouin Le Charlier <[email protected]>
Newsgroups gmane.comp.compilers.gpc
Message-ID <[email protected]>
  Hi everybody,

  I am trying to understand how to use {$I-} , {$I+} , and ioResult to check IO errors with text files. Il do not understand the following points.

It seems that {$I-} is not enough to disable the automatic handling of IO errors. You also have to actually write a call to ioResult in the program. Seems to me that this is not a correct behaviour. Moreover I do not understand how it is simply possible to have such a behaviour without using a kind of static analysis of the code. I join some files to show the problem. 

Thanks for your sharing your knowledge of {$I-} , {$I+} , and ioResult.

Baudouin



this program reads the file "toto.txt" without calling ioResult.



the same program with calls to ioResult



the file that is read by the program



execution of lireToto compiled with {$I-}



execution of lireToto compiled with {$I+}



execution of lireToto_ioResult compiled with {$I-}


execution of lireToto_ioResult compiled with {$I+}

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
lireToto.pas (application/octet-stream, 4.5 KB) - not displayed
lireToto_ioResult.pas (application/octet-stream, 4.6 KB) - not displayed
toto.txt (text/plain, 32 B)
a  
 -12lulu 

   
1.345 45 
 1a
executionDeLireToto_gpc_$I-.txt (text/plain, 307 B)
$ gp lireToto.pas 
$ ./lireToto
c = a ; ord(c) = 97
i = -12
s = lulu 
x =  1.345000000000000e+00
c =   ; ord(c) = 32
x =  1.000000000000000e+00
s = a
./lireToto: attempt to read past end of file `toto.txt' (error #454 at 1f53)
Trace/BPT trap
$ more toto.txt
a  
 -12lulu 

   
1.345 45 
 1a
$
executionDeLireToto_gpc_$I+.txt (text/plain, 307 B)
$ gp lireToto.pas 
$ ./lireToto
c = a ; ord(c) = 97
i = -12
s = lulu 
x =  1.345000000000000e+00
c =   ; ord(c) = 32
x =  1.000000000000000e+00
s = a
./lireToto: attempt to read past end of file `toto.txt' (error #454 at 253d)
Trace/BPT trap
$ more toto.txt
a  
 -12lulu 

   
1.345 45 
 1a
$
executionDeLireToto_ioResult_gpc_$I-.txt (text/plain, 354 B)
$ gp lireToto_ioResult.pas 
$ ./lireToto_ioResult 
ioResult = 0
c = a ; ord(c) = 97
ioResult = 0
i = -12
ioResult = 0
s = lulu 
ioResult = 0
x =  1.345000000000000e+00
ioResult = 0
c =   ; ord(c) = 32
ioResult = 0
x =  1.000000000000000e+00
ioResult = 0
s = a
ioResult = 454
c =   ; ord(c) = 32
$ more toto.txt
a  
 -12lulu 

   
1.345 45 
 1a
$
executionDeLireToto_ioResult_gpc_$I+.txt (text/plain, 418 B)
$ gp lireToto_ioResult.pas 
$ ./lireToto_ioResult
ioResult = 0
c = a ; ord(c) = 97
ioResult = 0
i = -12
ioResult = 0
s = lulu 
ioResult = 0
x =  1.345000000000000e+00
ioResult = 0
c =   ; ord(c) = 32
ioResult = 0
x =  1.000000000000000e+00
ioResult = 0
s = a
./lireToto_ioResult: attempt to read past end of file `toto.txt' (error #454 at 2540)
Trace/BPT trap
$ more toto.txt
a  
 -12lulu 

   
1.345 45 
 1a
$
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.