xsharp.eu • And again the old song about REF and NULL - Page 2
Page 2 of 2

And again the old song about REF and NULL

Posted: Wed Feb 07, 2018 10:40 am
by leon-ts
Robert,

I think this is not a "dirty" syntax, but somehow related to the syntax of set/get the value to/from the address stored in the pointer variable.

LOCAL p AS DWORD PTR

Assign an address:
p := 0x12345678 // abstract address

Write the value into memory at the address indicated by the variable:
DWORD(p) := 5 // put the value 5 to the memory at address 0x12345678

Read:
LOCAL n AS DWORD
n := DWORD(p)
I have implemented a quick fix in the compiler today. Chris will test it and if he sees no side effects then this will be part of the next build.
Glad to hear. Thank you!

Best regards,
Leonid

And again the old song about REF and NULL

Posted: Wed Feb 07, 2018 1:31 pm
by robert
Leonid,
Leonid wrote:Robert,

I think this is not a "dirty" syntax, but somehow related to the syntax of set/get the value to/from the address stored in the pointer variable.

LOCAL p AS DWORD PTR

Assign an address:
p := 0x12345678 // abstract address

Write the value into memory at the address indicated by the variable:
DWORD(p) := 5 // put the value 5 to the memory at address 0x12345678

Read:
LOCAL n AS DWORD
n := DWORD(p)
The DWORD(p) syntax works when p is a pointer and will dereference p and get the data from the address that p points to.

In your example z is a REF INT and not a pointer and therefore "(z)" should be the same as "z", using the general rule that parenthesis operators don't do something special, but are only used to indicate a priority for complex operations.
For example:

Code: Select all

LOCAL a, b, c as INT
a := 1
b := 2
c := (a) + (b)   // c will become 3 This is the same as c := a + b
                 // you don't expect any dereferencing here as well.
But apparently VO doesn't work that way, and that is why I called it "dirty".
It was never designed this way, of that I am sure.

Robert

And again the old song about REF and NULL

Posted: Wed Feb 07, 2018 2:19 pm
by leon-ts
Robert,

If you write like below the compiler does not produce errors:

Code: Select all

FUNCTION Func1(x AS INT, y AS INT, z REF INT) AS INT
    LOCAL p AS INT PTR

    p := @z
    IF (p != NULL)
        z := x * y
        INT(p) := x * y // same result
    ENDIF

RETURN x + y
Here, just one operation is divided into two stages.

p := @z
IF (p != NULL)

And the compiler already perceives this operation as correct.

Best regards,
Leonid

And again the old song about REF and NULL

Posted: Wed Feb 07, 2018 9:17 pm
by Chris
Hi Leonid,

Yes, this works, as you are creating a pointer to the var yourself. It works only for value types (strutures) though, like INT, LOGIC etc, you can't use that with classes.

In any case, good news is that Robert has already made the necessary changes and the original code compiles fine now! :)
It's looking good so far, nothing else is broken..

Chris