Page 1 of 1

Weird struct sizeof with static arrays

Posted: Fri May 17, 2024 11:14 am
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?

Re: Weird struct sizeof with static arrays

Posted: Fri May 17, 2024 11:20 am
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.

[no bug]Re: Weird struct sizeof with static arrays

Posted: Fri May 17, 2024 11:37 am
by juergenkulow