[erlang-questions] Passing data between Erlang and C port while preserving padding and alignment?
Frank Muller
frank.muller.erl@REDACTED
Fri Dec 7 05:21:31 CET 2018
Hi guys
Let assume the following C structure (I have a bunch of them, all
different):
struct foo {
int32 i32;
char c;
int64 i64;
char * p;
float f;
char * str[16];
};
When it gets compiled, GCC will add some padding to align data types (i.e
self-alignment). More info at:
http://www.catb.org/esr/structure-packing/
On the Erlang side, it is very easy to generate a binary which matches this
C structure field by field.
But it won’t work because of the padding :-/
Question: how can I derive the GCC's padding, and automatically add it to
my Erlang binary?
I am open to any generic/flexible solutions even if I have to auto-generate
these C structures (i.e meta-programming).
Thank you.
/Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181207/19cdf2b0/attachment.htm>
More information about the erlang-questions
mailing list