使用的typedef数组来声明一个新的类型 [英] Using typedef for an array to declare a new type

查看:88
本文介绍了使用的typedef数组来声明一个新的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何才能定义一个新的类型(标签)使用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 是一个函数,指针10 unsigned 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 type unsigned char[10], array of 10 unsigned char.

int fct_foo(array* arr)

says fct_foo is a function that takes a pointer to an array of 10 unsigned char as an argument and returns an int.

Without the typedef, that would be written as

int fct_foo(unsigned char (*arr)[10])

这篇关于使用的typedef数组来声明一个新的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆