Why is adsafe_tags[1] is not getting properly initialized?
// local string (via static)
#define SSTRL(varname, val) \
static const char varname[] = val
#define SSTRLEN(var) \
(sizeof(var) - 1)
struct scs_data_tag
{
uint16_t key_size;
uint16_t val_size;
char data[];
};
SSTRL(ADSAFE_KEY, "p.as.rsa");
SSTRL(ADSAFE_VAL_BAD, "0");
SSTRL(ADSAFE_VAL_GOOD, "1000");
#define ADSAFE_KV_BAD "p.as.rsa0"
#define ADSAFE_KV_GOOD "p.as.rsa1000"
struct scs_data_tag adsafe_tags[] = {
{SSTRLEN(ADSAFE_KEY), SSTRLEN(ADSAFE_VAL_BAD), ADSAFE_KV_BAD},
{SSTRLEN(ADSAFE_KEY), SSTRLEN(ADSAFE_VAL_GOOD), ADSAFE_KV_GOOD}
};
and in gdb I get this:
(gdb) p adsafe_tags
$7 = {{key_size = 8, val_size = 1, data = 0x8ce664 <adsafe_tags+4> "p.as.rsa0"}, {key_size = 11888, val_size = 29537, data = 0x8ce668 ".rsa0"}}
char data[];is this allowed in C?struct scs_data_tagif size ofdataisn't sepcifiedstruct s *p = malloc(sizeof *p + n * sizeof *p->fam);. Before C99 introduced FAMs, something similar to this was someties called "the struct hack".