I’m implementing a protocol in C++, and it’s an ongoing project therefore the protocol changes frequently, and I have to change the code accordingly.
Let’s say I define a message as follows:
struct Message {
const int MSG_LENGTH = 3; // sizeof(a) + sizeof(b)
uint8_t a;
uint16_t b;
};
Now I want to add a new field uint32_t c
into Message
, but I don’t want to manually change MSG_LENGTH
.
Is it possible to use some trick (macro or template) to achieve this?
Thanks.