<div dir="ltr"><div>Yes, i spent the last few hours debugging the lib's sources with gdb and everything was ok inside it. I saw the problem you pointed only within gambas debugger.<br></div><div><br></div><div>The point is, the array<i><span class="gmail-im">  "char bits[SIXBIT_LEN]"</span></i><span class="gmail-im"><i> </i>inside sixbit structure is filled by a pointer with some characters, from the second string parameter passed to the method called inside Gambas.</span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">The array looks Ok from position 8 on. Position 0 to 7 receive garbage from the argument's previous characters. As you said, misalignment issues...</span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">I'm not very experienced in this matter but will try to tweak the lib's sources. Do you have any suggestion?<br></span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">Thanks in advance,<br></span></div></div><br><div class="gmail_quote"><div dir="ltr">Em qui, 29 de nov de 2018 às 11:01, Benoît Minisini <<a href="mailto:g4mba5@gmail.com">g4mba5@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le 28/11/2018 à 13:39, gen braga a écrit :<br>
> Hi there,<br>
> <br>
> I'm trying to use a method from an external library whose signature is <br>
> as follow<br>
> <br>
> int __stdcall assemble_vdm( ais_state *state, char *str )<br>
> <br>
> ais_state is:<br>
> <br>
> #define SIXBIT_LEN   255<br>
> <br>
> typedef struct {<br>
>      unsigned char msgid;               //!< Message ID 0-31<br>
>      unsigned int  sequence;            //!< VDM message sequence number<br>
>      unsigned int  total;               //!< Total # of parts for the <br>
> message<br>
>      unsigned int  num;                 //!< Number of the last part stored<br>
>      char          channel;             //!< AIS Channel character<br>
>      sixbit        six_state;           //!< sixbit parser state<br>
> } ais_state;<br>
> <br>
> six_state is:<br>
> <br>
> typedef struct {<br>
>      char bits[SIXBIT_LEN];          //!< raw 6-bit ASCII data string<br>
>      char *p;                        //!< pointer to current character <br>
> in bits<br>
>      unsigned char remainder;        //!< Remainder bits<br>
>      unsigned char remainder_bits;   //!< Number of remainder bits<br>
> } sixbit;<br>
> <br>
<br>
Your structure has holes and alignment problems.<br>
<br>
In that case, the compiler will reorder the fields in memory <br>
arbitrarily, and the Gambas interpreter does not know how to deal with that.<br>
<br>
If you made the library, try to reorder the structure fields so that <br>
there is no hole nor alignment problems anymore.<br>
<br>
In the future, I may be able to associate Gambas structures with libffi <br>
structures, so that passing Gambas structure to extern functions <br>
eventually work in all cases. Alas, nothing sure !<br>
<br>
Regards,<br>
<br>
-- <br>
Benoît Minisini<br>
<br>
----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
</blockquote></div>