On Sun, May 31, 2020 at 11:26 AM, Timo Kokkonen <t...@iki.fi> wrote:
> On Sat, May 30, 2020 at 11:18 PM Gerhard Sittig <gerhard.sit...@gmx.net> 
> wrote:
> > - Check portability. Do you fill in structs and then send _these_
> >   to the wire? Might be convenient but need not work everywhere.
> >   It's probably better to accept the tedium and properly stream
> >   requests and responses for improved reliability. Notice that
> >   the tedium is less with the recently introduced conversion
> >   helpers which also advance their position in the stream.
>
> Code should be portable (?)  I'm aware of dangers different cpu
> architectures, but yes I'm "cheating" little bit by using a struct,
> but the struct is (on purpose) just an array of bytes. This allows referencing
> positions in the buffer conveniently...
> I can't think of portability issues with this approach, or am I
> missing something?

When you have a struct you want to send over the line "as is" and not want the 
compiler to optimize it (avoid padding), you should add 
"__attribute__((packed))".

E.g.:
struct __attribute__((packed)) my_packet {
    uint8_t my_unsigned_8_bit_field;
    int16_t my_signed_16_bit_field;
};

IIRC this works for clang and gcc.

Cheers
Frank



_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to