PeekA vs PeekB

Just starting out? Need help? Post your questions and find answers here.
dave@idea-tech.com
New User
New User
Posts: 4
Joined: Sat Mar 11, 2023 12:14 am

PeekA vs PeekB

Post 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)
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PeekA vs PeekB

Post by Caronte3D »

No bug, in the Hex function you must use the #PB_Byte flag
dave@idea-tech.com
New User
New User
Posts: 4
Joined: Sat Mar 11, 2023 12:14 am

Re: PeekA vs PeekB

Post by dave@idea-tech.com »

OK. Thank you very much!
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: PeekA vs PeekB

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply