Oxygen Basic
Programming => Problems & Solutions => Topic started by: jcfuller on May 03, 2018, 03:56:36 AM
-
Charles,
Wrong interpretation by me or ..?
I expected sizeof(intptr) = 8
James
use rtl64
#autodim off
use console
int* intptr
sys sys1
printl "sizeof intptr -> " sizeof(intptr)
printl "sizeof sys1 -> " sizeof(sys1)
wait
-
Hi James,
O2 always dereferences to the base type. So, an int will always have a sizeof 4 regardless of its pointyness.
Note that the string type is inherently a pointer, and therefore has a sizeof 8 on a 64bit system.
These rules aid consistent striding when iterating over arrays of variables.
Example of striding:
def stride @%1 += sizeof %1
dim double d[100]
double pd at @d
'
for i=1 to 100
pd+=4
stride pd
next
'results in d[] 4,8,12,16 ...
-
Could we perhaps use explicit sizeof(int*) to avoid such re-interpretation?
-
I'm not sure that fits in but I noticed that pointer-types, were not getting it right, so I'll fix them on the next release of O2.
-
Thanks Charles!