Oxygen Basic

Programming => Problems & Solutions => Topic started by: jcfuller on May 03, 2018, 03:56:36 AM

Title: sizeof issue??
Post by: jcfuller on May 03, 2018, 03:56:36 AM
Charles,
  Wrong interpretation by me or ..?
I expected sizeof(intptr) = 8
James

Code: [Select]
use rtl64
#autodim off
use console

int* intptr
sys sys1
printl "sizeof intptr -> " sizeof(intptr)
printl "sizeof sys1   -> " sizeof(sys1)
wait
Title: Re: sizeof issue??
Post by: Charles Pegge on May 03, 2018, 04:33:25 AM
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:
Code: [Select]
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 ...
Title: Re: sizeof issue??
Post by: Mike Lobanovsky on May 03, 2018, 11:24:05 AM
Could we perhaps use explicit sizeof(int*) to avoid such re-interpretation?
Title: Re: sizeof issue??
Post by: Charles Pegge on May 04, 2018, 01:23:03 AM
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.
Title: Re: sizeof issue??
Post by: Mike Lobanovsky on May 04, 2018, 02:06:24 AM
Thanks Charles!