Wow, I just finished doing something similar. The use of x-macros is definitely a little cleaner &#x2F; canonical than my approach, which instead &quot;recurses&quot; through a VA_MACRO. For an excellent guide on recursion in macros, see this article on how to abuse the C pre-processor: <a href="https:&#x2F;&#x2F;github.com&#x2F;pfultz2&#x2F;Cloak&#x2F;wiki&#x2F;C-Preprocessor-tricks,-tips,-and-idioms" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pfultz2&#x2F;Cloak&#x2F;wiki&#x2F;C-Preprocessor-tricks,...</a>.<p>In the end I end up defining structs like this:
SERIALIZER_STRUCT( structname, int8_t, field1, int16_t, field2, ... );<p>Initializing them like this:
structname instance = {.field1 = 1, .field2=2};<p>and serializing them like this:
SERIALIZER_SERIALIZE( structname, &amp;instance, bigbuff_ptr );<p>As for just using a packed structure, there are definitely caveats with some compilers (ie: compilers for embedded systems may not handle various edge-cases for misaligned access, particularly when dereferencing pointers to structs.)