[Gambas-user] Struct with Array Field
Jussi Lahtinen
jussi.lahtinen at gmail.com
Sun Apr 9 01:02:56 CEST 2023
Only reason to use structure is when you need to pass it to an external
function not written in Gambas. Otherwise, don't use it.
I'm quite sure you can write a function that automates the "someArray = New
someClass" task with static methods of the Class & Object classes, but
honestly I don't think there is much use for it. The problem is in
somewhere else.
Jussi
On Sat, Apr 8, 2023 at 9:12 PM Mayost Sharon <sharon at 455.co.il> wrote:
>
> ---------- Original Message -----------
> From: T Lee Davidson <t.lee.davidson at gmail.com>
> To: user at lists.gambas-basic.org
> Sent: Fri, 7 Apr 2023 13:08:35 -0400
> Subject: Re: [Gambas-user] Struct with Array Field
>
> > On 4/6/23 17:45, Jussi Lahtinen wrote:
> > >
> > > > In c terms which structure are interface for, strings and
> arrays are just pointer that are not initialized to a value until
> > > > something is assigned to them.
> > > >
> > > > When you do a mstrct = new mystruct it creates the structure
> with null pointers for those fields.
> > >
> > [snip]
> > >
> > > The topic was *objects *inside structure. They have only null
> pointers. Variables are valid without further actions.
> > > C does not have "new", but he was referring to the similar things that
> need to be done in C.
> > >
> > > Jussi
> >
> > Yes, the original topic was arrays (objects) in a structure. To help
> clarify
> > for the OP, I gave examples of what did or did not need to be explicitly
> > initialized in a structure. Brian's response was to make a false
> statement
> > which, to help prevent confusion, needed to be corrected.
> >
> > The statement, "When you do a mstrct = new mystruct it creates the
> structure
> > with null pointers for those fields," does not refer to what happens in
> C. And,
> > "those fields," obviously refers to "strings and arrays". As I
> explained, the
> > strings would be automatically initialized, but the arrays would not.
> >
> > Is there anything incorrect about the following statement?
> > Simple native datatypes (such as String, Integer, Boolean) will be
> > automatically initialized. But, objects (such as String[], Integer[],
> > Boolean[]), which are objects of classes and have properties and
> methods,
> > must be initialized with the NEW keyword.
> >
> > --
> > Lee
> >
> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> ------- End of Original Message -------
>
> If I have a structure that contains many array variables, etc.
> If I need to do NEW on every variable that is an array
> Why do I need it inside the structure?
> Is there a way in NEW once to execute on all variables?
>
> Thanks
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230409/20fa8e09/attachment.htm>
More information about the User
mailing list