[Gambas-user] Struct with Array Field

T Lee Davidson t.lee.davidson at gmail.com
Thu Apr 6 19:08:01 CEST 2023

On 4/6/23 02:35, Brian G 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.

To my knowledge C does not have a "new" expression/statement. So, you must be talking about Gambas behavior, and therfore your 
statement is incorrect. Try it for yourself and see what it prints:
Public Struct elevation
   a As Short
   b As Long
   c As Float
   d As String
End Struct

Public Sub main()
   Dim a As New Elevation
   Print a.a, a.b, a.c, a.d

BTW, top-posting leads to messy threads.
  ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
  ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
  ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> --
> Thanks
> Brian G
> Wednesday, 05 April 2023, 07:55AM -07:00 from T Lee Davidson t.lee.davidson at gmail.com <mailto:t.lee.davidson at gmail.com>:
>     On 4/5/23 10:57, Mayost Sharon wrote:
>      > first thanks
>      >
>      > Is it supposed to be like this?
>      > For each field that is an array I will have to say NEW separately
>      >
>      > The fields are inside a Struct
>      > I thought that if I do NEW to Struct
>      > This will do it on all fields
>      >
>      > Thanks
>     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


More information about the User mailing list