1

I'm trying to get a pointer to a double value within a struct that I can pass to a routine, but having trouble getting any value other than 0. The following has worked for other struct! values I've used (such as one containing only binary!), but not in this case:

Rebol []

speed1: make struct! [
    d [double]
] [0.0]
speed1*-struct: make struct! [i [int]] third speed1
speed1*: speed1*-struct/i

Here is the evaluation:

>>  speed1: make struct! [
[      d [double]
[     ] [0.0]
>>  speed1*-struct: make struct! [i [int]] third speed1
>>  speed1*: speed1*-struct/i
== 0

Here is the working equivalent with a binary! struct:

>>  binary: make struct! [bytes [binary!]] reduce [head insert/dup copy #{} 0 8]
>>  binary*-struct: make struct! [i [int]] third binary
>>  binary*: binary*-struct/i
== 39654648

I can see the difference in the third function:

>> third speed1
== #{0000000000000840}
>> third binary
== #{F8145D02}

However, I am not really sure what the difference in length means in this case. What am I doing wrong? Is there a different way to pass pointers to a decimal value?

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
kealist
  • 1,669
  • 12
  • 26

1 Answers1

0

Here is a way to get a pointer to a double value:

speed1-struct: make struct! [s [struct! [d [double]]]] [0.0]
speed1*-struct: make struct! [i [int]] third speed1-struct
speed1*: speed1*-struct/i

And the evaluation showing it returns a pointer (shown as int):

>> speed1-struct: make struct! [s [struct! [d [double]]]] [0.0]
>> speed1*-struct: make struct! [i [int]] third speed1-struct
>> speed1*: speed1*-struct/i
== 37329176
kealist
  • 1,669
  • 12
  • 26