Hi, thanks for your work! Really appreciate the clean api and efficiency it brings to the (vers)table.
In my use case, I have many tables as global state. As they are static and spread across multiple TUs, all of them previously needed a <module>_init() function that just calls vt_init for all contained tables.
To remove this need, I simply added this macro:
#define VT_INITED {.metadata = (uint16_t*)&vt_empty_placeholder_metadatum}
For better compatibility with pre-C99 and pre-C++20 it could also be defined as:
#define VT_INITED {0, 0x0000000000000000ull, NULL, (uint16_t*)&vt_empty_placeholder_metadatum}
#define VT_INITED_WITH_CTX(ctx) {0, 0x0000000000000000ull, NULL, (uint16_t*)&vt_empty_placeholder_metadatum, ctx}
This allows simply defining global tables like this without the need for any runtime initializer:
static my_table_t s_table = VT_INITED;
One thing I am unsure about with this design: Destructors still need to be called manually. Not avoidable, but this may be missed by users as you can easily forget about that if you do not ever call vt_init manually.
I still think this would be pretty useful addition. What do you think?
Best regards
Hi, thanks for your work! Really appreciate the clean api and efficiency it brings to the (vers)table.
In my use case, I have many tables as global state. As they are static and spread across multiple TUs, all of them previously needed a
<module>_init()function that just callsvt_initfor all contained tables.To remove this need, I simply added this macro:
For better compatibility with pre-C99 and pre-C++20 it could also be defined as:
This allows simply defining global tables like this without the need for any runtime initializer:
One thing I am unsure about with this design: Destructors still need to be called manually. Not avoidable, but this may be missed by users as you can easily forget about that if you do not ever call
vt_initmanually.I still think this would be pretty useful addition. What do you think?
Best regards