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

Re: Problem passing Array of Structs to external library


On 4/3/24 18:20, Jussi Lahtinen wrote:
Some mistakes. Object instead of embedded array and wrong order if the array.
See the attachment.


Jussi

Ah, I see. Got it. (And there the information was right there on the "Structure declaration" Wiki page which I obviously skimmed over too many times.)

It works great now.

Thank you, Jussi!


On Wed, Apr 3, 2024 at 8:00 PM T Lee Davidson <t.lee.davidson@xxxxxxxxx <mailto:t.lee.davidson@xxxxxxxxx>> wrote:

    I'm working with an external library that allows to pass an array of structures in the extra arguments of a variadic function.
    It does not work well with the array of structures that I try passing to it.

    With a C structure defined thusly:

    struct OptionItem
    {
        int option;
        intptr_t value;
        void *ptr_value;
    };

    ... it does work if a C function passes the following as "ops":

    struct OptionItem ops[] = {
    { OPTION_CONNECTION_TIMEOUT, 31, NULL },
    { OPTION_CONNECTION_LIMIT, 21, NULL },
    { OPTION_CONNECTION_MEMORY_LIMIT, 11, NULL},
    { OPTION_END, 0, NULL }
    };

    Isn't that an array of structures?

    Strangely, if I pass it just a single structure (instead of an array), it does not complain but actually parses it.

    Perhaps I am misunderstanding how this should work.

    I have taken source code from that shared library and pared it down to create a small library that demonstrates the issue. It,
    with its source code, is included in the project which is attached.

-- Lee

    --- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette <https://gambaswiki.org/wiki/doc/netiquette>] ----
    --- Gambas User List Archive [https://lists.gambas-basic.org/archive/user <https://lists.gambas-basic.org/archive/user>] ----



--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


References:
Problem passing Array of Structs to external libraryT Lee Davidson <t.lee.davidson@xxxxxxxxx>
Re: Problem passing Array of Structs to external libraryJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>