Weird struct sizeof with static arrays

Just starting out? Need help? Post your questions and find answers here.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Weird struct sizeof with static arrays

Post by Justin »

PB6.11 b2
Why sizeof returns 0?, should't be the pointer size?
With this behaviour is not possible to do this:

Code: Select all

Structure MYSTRUCT
	*arr.RECT[0]
EndStructure

Define.MYSTRUCT *st

Debug SizeOf(MYSTRUCT) ;0 ??
*st =  AllocateMemory(SizeOf(MYSTRUCT)) ;ERROR

;Not possible
*st\arr = AllocateMemory(SizeOf(RECT) * 4)
*st\arr[2]\left = 10
Could this be changed for the next version?
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Weird struct sizeof with static arrays

Post by STARGÅTE »

The static array with *arr.RECT[0] has no elements (not even index 0). It is no pointer to an array! It is an array of pointers.
So the size of the structure is correct to be 0. No Bug.

Code: Select all

*st\arr = AllocateMemory(SizeOf(RECT) * 4)
This syntax in anyway wrong, because *arr.RECT[n] is not one pointer to an array with n-1 elements, it is an array of n-1 pointers.
*st\arr = ... is the sort version of *st\arr[0] = ...

Edit: Please do not post in "Bug Reports" if you have a code question.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply