Problem: I would like to write a code sample that is cross-compatible between C and C++.
I have a plain ol' data (POD) struct like this for example...
typedef struct blob {
int size;
uint8_t * data;
} blob;
Is there a simple way to zero initialize this that is valid in both C and C++?
If I understand correctly, the following initializers are not valid in both languages:
blob b = {0}; // valid C, invalid C++
blob b = {}; // valid C++, invalid C
The best I've found so far is:
blob b = {0,0};
... which is okay, but the real struct has 8 fields and that's getting into typo territory.
Question: Is there a common convention used, or a cross-compatible way of initialization that doesn't require knowledge of the fields?