Author Topic: sizeof issue??  (Read 1472 times)

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Guest
sizeof issue??
« 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

Charles Pegge

  • Guest
Re: sizeof issue??
« Reply #1 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 ...
« Last Edit: May 03, 2018, 04:59:52 AM by Charles Pegge »

Mike Lobanovsky

  • Guest
Re: sizeof issue??
« Reply #2 on: May 03, 2018, 11:24:05 AM »
Could we perhaps use explicit sizeof(int*) to avoid such re-interpretation?

Charles Pegge

  • Guest
Re: sizeof issue??
« Reply #3 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.

Mike Lobanovsky

  • Guest
Re: sizeof issue??
« Reply #4 on: May 04, 2018, 02:06:24 AM »
Thanks Charles!