struct a *var = malloc(sizeof(*var) + n*sizeof(var->d[0]))
Using variables for sizeof ensures that the size will be updated if the types are changed. Otherwise, if you change the type d or var , you run the risk of introducing silent and potentially hard-to-reach problems at run time without allocating enough memory if you forget to update any of the corresponding distributions.
Kevin
source share