结构体定义中遇到的问题

ios_sheep 2014-11-24 02:31:43
typedef struct
{
uint16 Addr; // linked target's short address
uint16 profileID;
uint16 deviceID;
uint8 deviceVersion;
uint8 EP; // linked target's end-point
} zllRemoteLinkedTarget_t;

typedef struct
{
zllRemoteLinkedTarget_t arr[MAX_LINKED_TARGETS];
} zllRemoteLinkedTargetList_t;

这是我程序里面两个结构体的定义,zllRemoteLinkedTarget_t arr[MAX_LINKED_TARGETS]这一句我不太理解,希望有人能指点一下,谢谢!
能否将arr[MAX_LINKED_TARGETS]这个数组独立出来?
本人小白,还望大家不要见笑
...全文
175 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-11-24
  • 打赏
  • 举报
回复
typedef typedef type-declaration synonym; The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition. A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types. Example // Example of the typedef keyword typedef unsigned long ulong; ulong ul; // Equivalent to "unsigned long ul;" typedef struct mystructtag { int i; float f; char c; } mystruct; mystruct ms; // Equivalent to "struct mystructtag ms;" typedef int (*funcptr)(); // funcptr is synonym for "pointer // to function returning int" funcptr table[10]; // Equivalent to "int (*table[10])();"
skyliuxu 2014-11-24
  • 打赏
  • 举报
回复
typedef struct { uint16 Addr; // linked target's short address uint16 profileID; uint16 deviceID; uint8 deviceVersion; uint8 EP; // linked target's end-point } zllRemoteLinkedTarget_t; 这是声明了一种结构体类型是吧?类型名是zllRemoteLinkedTarget_t,每一个这种类型的对象呢包括那么一堆东西(Addr, profileID, blablabla)。好了,现在我想再声明一种结构体类型,这个类型的对象是一个数组,每个元素的类型是zllRemoteLinkedTarget_t,所以就 typedef struct { zllRemoteLinkedTarget_t arr[MAX_LINKED_TARGETS]; } zllRemoteLinkedTargetList_t; 这样喽。 你试着将zllRemoteLinkedTarget_t类比成int,就很好理解了
starytx 2014-11-24
  • 打赏
  • 举报
回复
引用 7 楼 xiaoxiaobaibaicai 的回复:
[quote=引用 5 楼 starytx 的回复:] 就是把第一个结构体的一个数组定义为一个新类型zllRemoteLinkedTargetList_t;
那个数组里面的内容是不是zllRemoteLinkedTarget_t结构体里面的各项的值?[/quote]是的。如果你需要多处定义第一个结构体的那种数组,就可以使用第二个那种来定义。比如: zllRemoteLinkedTargetList_t X; X.arr[0].Addr = 123;
ios_sheep 2014-11-24
  • 打赏
  • 举报
回复
引用 5 楼 starytx 的回复:
就是把第一个结构体的一个数组定义为一个新类型zllRemoteLinkedTargetList_t;
那个数组里面的内容是不是zllRemoteLinkedTarget_t结构体里面的各项的值?
williamhong 2014-11-24
  • 打赏
  • 举报
回复
就是只定义一个数组嘛,可以独立出来
starytx 2014-11-24
  • 打赏
  • 举报
回复
就是把第一个结构体的一个数组定义为一个新类型zllRemoteLinkedTargetList_t;
luo_miao 2014-11-24
  • 打赏
  • 举报
回复
引用 3 楼 luo_miao 的回复:
zllRemoteLinkedTargetList_t 起始就是一个 zllRemoteLinkedTarget_t 结构体的数组,有什么不理解的地方?
其实
luo_miao 2014-11-24
  • 打赏
  • 举报
回复
zllRemoteLinkedTargetList_t 起始就是一个 zllRemoteLinkedTarget_t 结构体的数组,有什么不理解的地方?
ios_sheep 2014-11-24
  • 打赏
  • 举报
回复
引用 1 楼 focuslight 的回复:
typedef struct { zllRemoteLinkedTarget_t arr[MAX_LINKED_TARGETS]; } zllRemoteLinkedTargetList_t; 这个没写全, 少指针
这个是ti给的程序,木有问题啊
Isnis-fallen 2014-11-24
  • 打赏
  • 举报
回复
typedef struct { zllRemoteLinkedTarget_t arr[MAX_LINKED_TARGETS]; } zllRemoteLinkedTargetList_t; 这个没写全, 少指针

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧