And again the old song about REF and NULL

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

And again the old song about REF and NULL

Post 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
Best regards,
Leonid
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

And again the old song about REF and NULL

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

And again the old song about REF and NULL

Post 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
Best regards,
Leonid
User avatar
Chris
Posts: 4907
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

And again the old song about REF and NULL

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply