S
Shao Miller
Good day to all.
In another C-devoted forum, there appeared to be consensus that using
macros to automatically expand as code for serializing and deserializing
and defining structures was not worth the trade-off between redundancy
and legibility.
This is a quick poll of opinion here, if you please.
Some advantages:
- All source remains within the scope of C
- Less typing
Some disadvantages:
- More challenging for humans to interpret
- Partial C parsers such as IDEs won't likely be able to determine
structure definitions and definition locations
As quick example:
#define M_TEST(B_, U_, T_, N_, D_, E_) \
\
B_(test) \
U_(T_(M_SER_TD_BE_U16), N_(alpha), D_("The alpha member")) \
U_(T_(M_SER_TD_BE_U8), N_(beta), D_("The beta member")) \
U_(T_(M_SER_TD_BE_U32), N_(gamma), D_("The gamma member")) \
E_
which could be expanded by various macros into various declarations,
definitions, and statements. Is that just way too ugly?
A suggestion was that a specification file could be easier to read and
another tool could auto-generate C source code. An enhancement of that
suggestion was that the spec. file could even resemble C! If so, what
might be a pleasant way to mark up a struct definition with meta-data?
Would something like:
struct foo {
SERIALIZE_WITH_MEMCPY char some_array[20];
SERIALIZE_AS_BEUINT32 uint32_t some_uint;
};
be pleasant? Or what about:
struct foo {
char __XXX(SERIALIZE_WITH_MEMCPY) some_array[20];
uint32_t __XXX(SERIALIZE_WITH_MEMCPY) some_uint;
};
? What do you think? Thanks!
In another C-devoted forum, there appeared to be consensus that using
macros to automatically expand as code for serializing and deserializing
and defining structures was not worth the trade-off between redundancy
and legibility.
This is a quick poll of opinion here, if you please.
Some advantages:
- All source remains within the scope of C
- Less typing
Some disadvantages:
- More challenging for humans to interpret
- Partial C parsers such as IDEs won't likely be able to determine
structure definitions and definition locations
As quick example:
#define M_TEST(B_, U_, T_, N_, D_, E_) \
\
B_(test) \
U_(T_(M_SER_TD_BE_U16), N_(alpha), D_("The alpha member")) \
U_(T_(M_SER_TD_BE_U8), N_(beta), D_("The beta member")) \
U_(T_(M_SER_TD_BE_U32), N_(gamma), D_("The gamma member")) \
E_
which could be expanded by various macros into various declarations,
definitions, and statements. Is that just way too ugly?
A suggestion was that a specification file could be easier to read and
another tool could auto-generate C source code. An enhancement of that
suggestion was that the spec. file could even resemble C! If so, what
might be a pleasant way to mark up a struct definition with meta-data?
Would something like:
struct foo {
SERIALIZE_WITH_MEMCPY char some_array[20];
SERIALIZE_AS_BEUINT32 uint32_t some_uint;
};
be pleasant? Or what about:
struct foo {
char __XXX(SERIALIZE_WITH_MEMCPY) some_array[20];
uint32_t __XXX(SERIALIZE_WITH_MEMCPY) some_uint;
};
? What do you think? Thanks!