我知道如何使用typedef来定义新类型(label)。
例如,typedef unsigned char int8表示可以使用“int8”声明无符号char类型的变量。
但是,我不明白以下声明的含义:

typedef unsigned char array[10]

这是否意味着数组是无符号char[10]类型?
在代码的其他部分中,此类型用作函数参数:
int fct_foo(array* arr)

有人熟悉这个说法吗?

最佳答案

这是否意味着数组的类型是unsigned char[10]
将“of”替换为“the”的另一个名称,您的语句100%正确。atypedef为类型引入新名称。

typedef unsigned char array[10];

array声明为类型unsigned char[10]的另一个名称,数组为10unsigned char
int fct_foo(array* arr)

saysfct_foo是一个函数,它将指向10unsigned char数组的指针作为参数并返回int
如果没有typedef,将被写为
int fct_foo(unsigned char (*arr)[10])

07-24 09:47
查看更多