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

0 Members and 1 Guest are viewing this topic.

jcfuller

  • Full Member
  • ***
  • Posts: 143
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

  • Admin Support Member
  • *****
  • Posts: 3745
    • Oxygen Basic
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

  • Admin Support Member
  • *****
  • Posts: 1856
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?
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3745
    • Oxygen Basic
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

  • Admin Support Member
  • *****
  • Posts: 1856
Re: sizeof issue??
« Reply #4 on: May 04, 2018, 02:06:24 AM »
Thanks Charles!
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)