使用的typedef数组来声明一个新的类型 [英] Using typedef for an array to declare a new type
问题描述
我知道如何才能定义一个新的类型(标签)使用typedef。
例如,的typedef unsigned char型INT8
意味着您可以使用INT8声明unsigned char类型的变量。
不过,我无法理解以下说明书的含义是:
的typedef unsigned char型数组[10]
这是否意味着数组为unsigned char型的[10]?
在code的另一部分,这种类型被用作函数参数:
INT fct_foo(数组* ARR)
是否有任何人谁是熟悉这种说法?
这是否意味着数组类型的
unsigned char型[10]
?
块引用>替换的的 的用的另一名的和你有一个 100%正确的语句。 A
的typedef
引入了一个新的名称为一个类型。的typedef unsigned char型数组[10];
声明
阵列
的另一个名称类型unsigned char型[10]
10 <$ C $的数组C> unsigned char型。INT fct_foo(数组* ARR)
说
fct_foo
是一个函数,指针10unsigned char型
数组作为参数,返回一个INT
。如果没有
的typedef
,那会被写成INT fct_foo(无符号字符(* ARR)[10])
I know how to use typedef in order to define a new type (label).
For instance,
typedef unsigned char int8
means you can use "int8" to declare variables of type unsigned char.However, I can't understand the meaning of the following statment:
typedef unsigned char array[10]
Does that mean array is of type unsigned char[10]?
In other part of code, this type was used as a function argument:
int fct_foo(array* arr)
Is there anyone who is familiar with this statement?
解决方案Does that mean array is of type
unsigned char[10]
?Replace "of" with "another name for the" and you have a 100% correct statement. A
typedef
introduces a new name for a type.typedef unsigned char array[10];
declares
array
as another name for the typeunsigned char[10]
, array of 10unsigned char
.int fct_foo(array* arr)
says
fct_foo
is a function that takes a pointer to an array of 10unsigned char
as an argument and returns anint
.Without the
typedef
, that would be written asint fct_foo(unsigned char (*arr)[10])
这篇关于使用的typedef数组来声明一个新的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!