[Gambas-user] Arrays of Structs - how to - and curious debug message
g4mba5 at gmail.com
Thu Jun 10 22:17:48 CEST 2021
Le 10/06/2021 à 21:10, John Anderson a écrit :
> I've come across an issue I'm trying to solve in Gambas. I KNOW I'm
> doing this wrong, and I'm being dumb - but maybe somebody can point the
> way. I can't find any more deets online, and the examples about structs
> are kind of scarce. But that's not the interesting part...what's
> interesting is how Gambas decides to NOT flag an error, but maybe I have
> that wrong too.
> ...too much text to read at 22 PM
1) Please compress your project archives when you post on the mailing-list.
2) Apparently you didn't read the wiki page on structure declarations.
Especially the last paragraph "Arrays of structure".
If you declare that:
Public Struct Foo
A As Integer
B As Boolean
C As String
Private $aArray As Struct Foo ' Note the Struct keyword before Foo
Then $aArray will be an array of sixteen Foo structures allocated in one
slot successively in memory, like the C language does.
For Gambas, $aArray is a special variable of type "array of structure".
It's not a real array, so you will not have all the methods of the
standard Array class. It's really for send it to some C code.
Note that a structure declaration can be used like a class with just
public variables. It's what you did when declaring:
Dim var As New StructureName
In other words:
As StructName -> declare a pointer to a structure allocated like a
As Struct StructName -> embeds a structure directly inside a variable or
another structure, like C does by default.
So be careful!
If you find the wiki page not clear enough, do not hesitate to fix it.
More information about the User