Reputation: 1873
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?
Upvotes: 1
Views: 74
Reputation: 5054
To understand what's going on, you have to breakdown the code part by part
typedef int32_t voltage_dc_estimate_t[1];
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
typedef int32_t voltage_dc_estimate_t;
if you are only trying to save 1 element.
Upvotes: 1
Reputation: 141554
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
.
Upvotes: 0
Reputation: 122383
[1]
means an array of 1
element.
voltage_dc_estimate_t
is a type of an array of 1
element of type int32_t
.
Upvotes: 3