Memset In C Using Sizeof Operator : -


here struct :

typedef struct tag_device_sys {     char device[string_size];     int id;     char category; } device_sys; 

for memset, 1 should used below ?

memset(dev_sys, 0, (size_t)num_devices * sizeof(device_sys)); 

or

memset(dev_sys, 0, (size_t)num_devices * sizeof(dev_sys)); 

what differences ?

i use objects arguments sizeof

struct whatever *ptr; /* ... */ ptr = malloc(nelems * sizeof *ptr); memset(ptr, 0, nelems * sizeof *ptr); 

the advantage on using parenthesized type code needs changed @ 1 place should type of data change

struct before_change *ptr; /* ... */ ptr = malloc(nelems * sizeof (struct before_change)); memset(ptr, 0, nelems * sizeof (struct before_change)); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -