2022-05-24

Can {0} initialize a stucture (local) variable several times correctly

I've noticed that inside a library of STM32, there is a piece of the code which initialize a stucture variable with {0}. Below is a simplified example:

   typedef struct
    {
        uint16_t           val_a;  
        uint16_t           val_b;
        uint16_t           val_c;
    } dataset_t;
dataset_t Dataset = {0};

The goal of this code is to initialize all the elements of the variable Dataset to 0. Is this a correct way to initialize this variable ? Is it possible that this method initialize only the first element (val_a) to 0, but not all the elements if we initialize this many times ?



No comments:

Post a Comment