user2793162
user2793162

Reputation:

Confused with typedef usage

I encountered code where:

typedef wchar_t     str_param_t[WP_STR_MAX_LEN];

And then:

typedef struct work_t
{
    u32_t           val1;
    u32_t           val2;
    str_param_t     data[WP_MAX_COUNT_STR];
} work_t;

My question is what type is data?

Upvotes: 2

Views: 92

Answers (3)

BlackMamba
BlackMamba

Reputation: 10252

the type of data is 2D array of type wchar_t.

typedef wchar_t     str_param_t[WP_STR_MAX_LEN];
str_param_t     data[WP_MAX_COUNT_STR];

this is equal to:

wchar_t data[WP_STR_MAX_LEN][WP_MAX_COUNT_STR];

Upvotes: 2

Jayesh Bhoi
Jayesh Bhoi

Reputation: 25915

Let me explain you in simple about typedef

Like

typedef string FiveStrings[5];

By defining typedef string FiveStrings[5], FiveStrings can be used to declare an array of 5 strings with each string being of type string(char *).

Now you can use above new type name as follows

FiveStrings countries = { "Ghana", "Angola", "Togo",

                          "Tunisia", "Cote d'Ivoire" };

Upvotes: 1

Gassa
Gassa

Reputation: 8874

It is an array of length WP_MAX_COUNT_STR containing wchar_t-based strings of length WP_STR_MAX_LEN each.

Upvotes: 4

Related Questions