[Gambas-user] Struct with Array Field

T Lee Davidson t.lee.davidson at gmail.com
Fri Apr 7 19:08:35 CEST 2023


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



More information about the User mailing list