Page 1 of 1

PeekA vs PeekB

Posted: Tue Mar 21, 2023 6:33 pm
by dave@idea-tech.com
Hello,

Firstly, I'd like to say that developing with PureBasic is fantastic experience!
Thank You!

I have discovered an oddity that may be a bug, or perhaps just needs better documentation
in the user manual.

I was using PeekB to view the contents of memory and was confused with all of the $FF
values that were in the memory.

When I changed from PeekB to PeekA, the memory was displayed correctly.

Here is a test program to show what I mean.

Code: Select all

; PeekA vs PeekB printed as a hex value 

; when I run this program with the line 1 then PeekB results in negative
; numbers being printed out. This is expected

; when I run this program with line 2 then PeekB results in $FF for all byte values 
; greater than $7F ( 128 decimal ). This was not expected and caused confusion

Dim some_array.b(255)
Define *p = @some_array(0)

For i = 0 To 255
  some_array(i) = i
  
  ;Line 1
  Debug "PeekA(" + Str(i) + ") = " + Str(PeekA(*p+i)) + " , but PeekB(" + Str(i) + ") = " + Str(PeekB(*p+i))
  
  ; Line 2
  ;Debug "PeekA(" + Str(i) + ") = " + RSet( Hex(PeekA(*p+i)), 2, "0" ) + " , but PeekB(" + Str(i) + ") = " + RSet( Hex(PeekB(*p+i)), 2, "0" )
Next

// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)

Re: PeekA vs PeekB

Posted: Tue Mar 21, 2023 7:11 pm
by Caronte3D
No bug, in the Hex function you must use the #PB_Byte flag

Re: PeekA vs PeekB

Posted: Tue Mar 21, 2023 7:18 pm
by dave@idea-tech.com
OK. Thank you very much!

Re: PeekA vs PeekB

Posted: Tue Mar 21, 2023 8:50 pm
by jacdelad
Signed vs. unsigned variable: Your loop creates an overflow ("b" is signed, "a" is unsigned)! Since *p is a pointer you can read its content regardless of interpretion.