Results 1 to 3 of 3

Thread: Data type of pointer

  1. #1
    Junior Member
    Join Date
    Dec 2023
    Posts
    24
    Rep Power
    4

    Data type of pointer

    If I want to do a PEEK of a memory address that I got from VARPTR, then I need to know the data type of a pointer, right? So what is the data type of a pointer? I mean, obviously it's a numeric data type, and it's a memory address, so it can't be BYTE.

  2. #2
    Junior Member
    Join Date
    Dec 2023
    Posts
    24
    Rep Power
    4

    Well, I didn't NEED to know

    I double checked the manual on PEEK, and saw that specifying the type was optional. This is the little experiment I was fooling with. I tried calling VARPT with PEEK and that gave me the value at the variable.

    USES "CONSOLE"                                  
    REM First, we declare variables a, b, and c     
    DIM a AS BYTE                                   
    DIM b AS BYTE                                   
    DIM c AS BYTE                                   
    REM Second, we assign a value to each variable  
    a = 1                                           
    b = 2                                           
    c = 3                                           
    REM Third, we print the address of each variable
    PRINTL VARPTR(a)                          
    PRINTL VARPTR(b)                                
    PRINTL VARPTR(c)
    
    So, I tried doing "PRINTL PEEK(VARPTR(a))" and that gave me the value at the variable, so I know that if I have the value stored at the pointer, I can use PEEK to get the value stored in the variable. I'm sure this is patently obvious to anyone that knows what they're doing.
    Last edited by Benjamin; 20-12-2023 at 04:18.

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10
    A pointer is a number that points to a memory area.

    thinBasic is a 32bit only process so under 32bit process, a pointer is 32bit so usually a DWORD but also a LONG is OK (internally the sign bit will not be interpreted as sign but will be part of the addressing)

    Under a 64bit process, memory addressing pointer is represented by a QUAD (64 bit number)

    What is allocated into a memory area and how it is interpreted is responsibility of the process and programmer.
    The Operating system is just responsible of allocating/deallocating but how that memory are is interpreted is not a OS job.
    The same memory area con be interpreted ad a number or a string or a type or whatever.

    Just an example
    USES "CONSOLE"                                 
    REM First, we declare variables a, b, and c     
    DIM a AS BYTE                                  
    DIM b AS BYTE                                  
    DIM c AS BYTE                                  
    REM Second, we assign a value to each variable  
    a = 1                                           
    b = 2                                           
    c = 3                                           
    REM Third, we print the address of each variable
    printl "Defined 3 byte var: a, b, c, d"
    printl "Values of a, b, c...........:", a,b,c
    PRINTL "Varptr of a, b, c...........:", VARPTR(a), VARPTR(b), VARPTR(c)
    PRINTL "Peek(Varptr) of a, b, c.....:", peek(byte, VARPTR(a)), peek(byte, VARPTR(b)), peek(byte, VARPTR(c))
    printl "-----------------------------"
    
    
    dim nLong as Long
    nlong = 1234567898
    printl "Defined 1 long var: nLong"
    printl "Values nLong...............:", nLong
    PRINTL "Varptr of nLong............:", VARPTR(nLong)
    PRINTL "Peek(Varptr) of nLong......:", peek(long, VARPTR(nLong))
    printl "-----------------------------"
    
    
    dim bArray(4) as byte at varptr(nLong)
    printl "Defined 1 array of 4 bytes at the memory location of nLong so the memory holding nLong can be interpreted in a different way"
    printl "Values bArray(1)...............:", bArray(1)
    printl "Values bArray(2)...............:", bArray(2)
    printl "Values bArray(3)...............:", bArray(3)
    printl "Values bArray(4)...............:", bArray(4)
    PRINTL "Varptr bArray..................:", VARPTR(bArray(1)), "Should be the same as VARPTR(nLong) above"
    
    
    WaitKey
    
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Parameter data type parsing BUG
    By xLeaves in forum thinBasic General
    Replies: 4
    Last Post: 12-08-2019, 10:36
  2. Strings and data type
    By Henry in forum File
    Replies: 2
    Last Post: 28-06-2011, 12:56
  3. Type pointer var not supported by WITH?
    By Michael Hartlef in forum thinBasic General
    Replies: 9
    Last Post: 24-09-2008, 15:42

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •