Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: STATIC elements in UDT

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    STATIC elements in UDT

    Next thinBasic preview will have STATIC UDT Elements.
    _________________________________________________
    Static elements are elements in common to all UDT variables derived from the same UDT TYPE.
    They are not part of the UDT structure itself but are available to all UDT of the same type.
    Static variables retain their values as long as the program is running.

    See following example:

    [code=thinbasic]
    uses "console"

    type tUDT
    '---Static elements will retains their values for the run of the application
    '---Static elements are in common to all variables of type TUDT
    static sLong as long
    static sLong2 as long
    static sStr as string
    static MyStaticArray(10) as long
    static MyStaticStringArray(100) as string

    lLong as long

    end type

    dim MyUDT_1 as tUDT
    dim MyUDT_2 as tUDT

    MyUDT_1.lLong = 123
    MyUdt_1.sLong = 999

    MyUdt_1.sStr = "Whatever string can be applied to a string static element"

    printl "Size of MyUDT is: " & sizeof(MyUDT_1.lLong)
    printl string$(70, "-")
    printl " MyUDT_1.lLong:", MyUDT_1.lLong
    printl " MyUDT_1.sLong:", MyUDT_1.sLong
    printl " MyUDT_2.sLong:", MyUDT_2.sLong
    printl " MyUDT_2.sStr :", MyUDT_1.sStr
    printl string$(70, "-")

    MyUdt_1.sLong = MyUdt_1.sLong + 999
    printl " MyUDT_2.sLong:", MyUDT_2.sLong
    printl string$(70, "-")

    MyUdt_1.MyStaticArray(10) = 10
    printl " MyUdt_1.MyStaticArray(10):", MyUdt_1.MyStaticArray(10)
    printl string$(70, "-")

    MyUdt_1.MyStaticStringArray(9 = "Again whatever string alloved in a static string element."
    MyUdt_2.MyStaticStringArray(99) = "Static elements are in common to all UDT of the same type"
    MyUdt_2.MyStaticStringArray(100) = "so changing in one variable will also effect all the others."
    printl " MyUdt_2.MyStaticStringArray( 9:", MyUdt_2.MyStaticStringArray(9
    printl " MyUdt_1.MyStaticStringArray( 99):", MyUdt_1.MyStaticStringArray(99)
    printl " MyUdt_1.MyStaticStringArray(100):", MyUdt_1.MyStaticStringArray(100)
    printl string$(70, "-")

    printl
    waitkey
    [/code]
    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

  2. #2

    Re: STATIC elements in UDT


    Hi Eros,

    You are getting dangerously close to OOP - when some of the static members become function pointers..

    Charles

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: STATIC elements in UDT

    Very interesting Eros,

    so kind of shared properties? Are those values linked using pointers and "decoded" at the time when accessing them? Will those members look as DWORD pointer values when passing them to external functions? Is there life in Space?
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: STATIC elements in UDT

    Quote Originally Posted by Petr Schreiber
    Very interesting Eros,

    so kind of shared properties? Are those values linked using pointers and "decoded" at the time when accessing them? Will those members look as DWORD pointer values when passing them to external functions? Is there life in Space?
    I'm sure there is life in space (we live in space ). I'm not sure about other questions
    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

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: STATIC elements in UDT

    Quote Originally Posted by Charles Pegge

    Hi Eros,

    You are getting dangerously close to OOP - when some of the static members become function pointers..

    Charles
    I'm making a preparatory work.
    STATIC is the first step.
    Simple METHODs will be the second.

    In my mind I want UDTs compatible with CLASSEs and used interchangeably when possible.
    Anyhow there will be a lot of work (I suppose months) before having something usable.

    Adding basic STATIC handling was quite easy but not yet finished. I'm now working to inject this possibility in all places where an UDT element is allowed.

    We will see.

    Eros

    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

  6. #6

    Re: STATIC elements in UDT

    Hi Eros,

    Thinking about O2 compatibility:

    Will the UDTs contain a pointer to the static members or are the static members mapped externally by thincore?

    Charles

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: STATIC elements in UDT

    Every UDT, among other things, has a pointer to a hash table containing name/data pairs of STATIC elements.
    Data is than another structure, the same used for standard variables.
    For each of them I can produce data PTR or structure info PTR but of course those are not compatible with O2.

    I do not know if I can be O2 compatible but I will think about it before going too much deeper.
    For Classes, you mainly have as first element a PTR to a virtual table containing pointers to static members and methods? Is this right?
    I need to study O2 sources and see what I can do.

    Eros
    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

  8. #8

    Re: STATIC elements in UDT


    Yes Eros it is like a C++ or COM object. The first element is a pointer to a virtual table which may include both class static elements and function pointers.

    The reason for including this pointer in the body of the object is to allow external systems to invoke the object. If the objects are for internal use only, the compiler/interpreter knows where the function table is and would have no problem in pushing its pointer directly onto the stack whenever an object method is called.

    But having this pointer in the UDT would enable thinBasic to invoke O2 objects directly and vice-versa.

    Charles



  9. #9
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: STATIC elements in UDT

    I love reading about what is going on here... it is making my day! The first steps to oop in thinbasic, woo hoo and clean ties to o2.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: STATIC elements in UDT

    wait wait wait

    We are just at the beginning testing and thinking about possible directions.
    A lot of water have to pass under the bridge before having something usable.

    But we will try!

    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

Page 1 of 2 12 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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