Either
memset(&dev_sys, 0, sizeof dev_sys);
or
memset(dev_sys, 0, NUM_DEVICES * sizeof(struct device_sys));
Or, if you prefer
memset(dev_sys, 0, NUM_DEVICES * sizeof *dev_sys);
but not what you have in your original variant.
Note, that in your specific case in all variants you can use either &dev_sys
or dev_sys
as the first argument. The effect will be the same. However, &dev_sys
is more appropriate in the first variant, since if follows the memset(ptr-to-object, object-size)
idiom. In the second and third variants it is more appropriate to use dev_sys
(or &dev_sys[0]
), since it follows the memset(ptr-to-first-element, number-of-elements * element-size)
idiom.
P.S. Of course, instead of using all that hackish memset
trickery, in your particular case you should have just declared your array with an initializer
struct device_sys dev_sys[NUM_DEVICES] = { 0 };
No memset
necessary.