[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Receive a pointer to a struct from an external function ?


Le 15/02/2026 à 22:10, Lee a écrit :
While working with Libc, I encountered an issue when receiving a pointer to a structure from an external function.

The C structure contains members which are declared as "char *". I declared the Gambas structure with those members "As String". But, attempting to print the string values causes a Segmentation Fault.

If those very members are declared "As Pointer", using String@ to print the values works.

Is this a bug in the external interface, an unrealistic expectation on my part, or something I am doing incorrectly?

Project attached.



Inside a Gambas structure, a String is a Gambas string, and only Gambas can create it. So if you use it to store a C string (a 'char *'), you need to use a Pointer.

It's only for function argument and function return value that you can use the Gambas String datatype, provided that you use it correctly as explained in the wiki.

In other words, you really need to know how C works to understand what you can do, and how you can do it in all cases.

Regards,

--
Benoît Minisini.


References:
Receive a pointer to a struct from an external function ?Lee <t.lee.davidson@xxxxxxxxx>