[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Receive a pointer to a struct from an external function ?
[Thread Prev] | [Thread Next]
- Subject: Re: Receive a pointer to a struct from an external function ?
- From: gbWilly <gbWilly@xxxxxxxxxxxxxx>
- Date: Mon, 16 Feb 2026 03:20:46 +0000
- Cc: user@xxxxxxxxxxxxxxxxxxxxxx
On Sunday, February 15th, 2026 at 22:34, Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> wrote: > 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. > This confirms what I encountered. First I used the String and Integer data types in my Struct and it didn't work. Changing all to Pointers and using String@ and Integer@ to show the data did work. Good to know it is different that the arguments. Thanks you for the clear explanation. gbWilly GambOS Gambas3 for Debian/Ubuntu ...there is always a Catch if things go wrong!
| Receive a pointer to a struct from an external function ? | Lee <t.lee.davidson@xxxxxxxxx> |
| Re: Receive a pointer to a struct from an external function ? | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |