I am confused about this example:
typedef int32_t voltage_dc_estimate_t[1];
Everything is OK but that [1]
at the end of the type definition confuse me. Could someone please help me to understand that situation?
To understand a typedef
declaration, first understand what the declaration would be without it:
int32_t voltage_dc_estimate_t[1];
That would declare an array of uint32_t
of length 1
, named voltage_dc_estimate_t
.
The effect of typedef
is that the name voltage_dc_estimate_t
will represent the type of that variable instead of being an actual variable. So in your example it means an array of int32_t
of length 1
.
To understand what's going on, you have to breakdown the code part by part
typedef is declaring a new type called voltage_dc_estimate_t, which is an array of int32_t of size 1.
Note that while this logical sense, it is a very bad idea to do this, because you are better off just doing
if you are only trying to save 1 element.