@BPokeStr vs. @BRead

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
C:\temp>ver /r
TCC 10.00.70 Windows XP [Version 5.1.2600]
TCC Build 70 Windows XP Build 2600 Service Pack 3
Registered to Howard Goldstein - 1 System License
C:\temp>set h=%@balloc[80]
C:\temp>echo %@bpokestr[%h,0,a,ABCDEFGHIJ]
0
C:\temp>echo %@bpeekstr[%h,0,a,10]
ABCDEFGHIJ
C:\temp>type insert.txt
Insert
C:\temp>set f=%@fileopen[insert.txt,r]
C:\temp>echo %@bread[%h,0,%f,0,6]
6
C:\temp>echo %@bpeekstr[%h,0,a,10]
InsertGHIJ
C:\temp>echo %@bpokestr[%h,0,a,xyz]
0
C:\temp>echo %@bpeekstr[%h,0,a,10]
xyz
C:\temp>

Note that @BRead does not truncate the buffer but @BPokeStr does. Is this
WAD? I don't see anything about this behavior in the help topics.

--
Howard
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#2
Howard Goldstein wrote:


> C:\temp>set h=%@balloc[80]
> C:\temp>echo %@bpokestr[%h,0,a,ABCDEFGHIJ]
> 0
> C:\temp>echo %@bpeekstr[%h,0,a,10]
> ABCDEFGHIJ
> C:\temp>type insert.txt
> Insert
> C:\temp>set f=%@fileopen[insert.txt,r]
> C:\temp>echo %@bread[%h,0,%f,0,6]
> 6
> C:\temp>echo %@bpeekstr[%h,0,a,10]
> InsertGHIJ
> C:\temp>echo %@bpokestr[%h,0,a,xyz]
> 0
> C:\temp>echo %@bpeekstr[%h,0,a,10]
> xyz
> C:\temp>
>
> Note that @BRead does not truncate the buffer but @BPokeStr does. Is this
> WAD? I don't see anything about this behavior in the help topics.
WAD. @BPOKESTR doesn't truncate the buffer; however it does write the
trailing null in the string to the buffer. So if you try to display
your binary data as text, TCC will only output the data up to the first
null.

Rex Conn
JP Software
 
May 29, 2008
517
3
Groton, CT
#3
C:\temp>ver /r
TCC 10.00.70 Windows XP [Version 5.1.2600]
TCC Build 70 Windows XP Build 2600 Service Pack 3
Registered to Howard Goldstein - 1 System License
C:\temp>set h=%@balloc[80]
C:\temp>echo %@bpokestr[%h,0,a,ABCDEFGHIJ]
0
C:\temp>echo %@bpeekstr[%h,0,a,10]
ABCDEFGHIJ
C:\temp>type insert.txt
Insert
C:\temp>set f=%@fileopen[insert.txt,r]
C:\temp>echo %@bread[%h,0,%f,0,6]
6
C:\temp>echo %@bpeekstr[%h,0,a,10]
InsertGHIJ
C:\temp>echo %@bpokestr[%h,0,a,xyz]
0
C:\temp>echo %@bpeekstr[%h,0,a,10]
xyz
C:\temp>

Note that @BRead does not truncate the buffer but @BPokeStr does. Is this
WAD? I don't see anything about this behavior in the help topics.
(In addition to what Rex wrote,) I think that it's necessary that @BREAD does not write anything into the buffer other than what was in the file. In general, ANYTHING could be in the file, not necessarily ASCII text.

Rex, the documentation on @BPOKESTR doesn't mention the fact that a trailing null is written. I had never used @BPOKESTR before and hadn't noticed it. Please add the warning that a terminating null is written.
(And perhaps there could be an option to inhibit it.)