首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请解释这个结构体的用法

请解释这个结构体的用法
EN

Stack Overflow用户
提问于 2013-03-23 18:08:23
回答 3查看 93关注 0票数 0
代码语言:javascript
复制
#define MAX_THREADS ( 17 )
struct thread_info
{
  unsigned int * thread_sp; /* Storage space for thread stack-pointer. */
  int thread_id;            /* Storage space for a thread ID. */
};
struct thread_info thread_info_array[ MAX_THREADS ];

我不明白第二个结构,你能解释一下它是做什么的吗?如果我们改变常量,常量是如何改变结构的?

更新

我认为这是一样的:

代码语言:javascript
复制
struct thread_info { unsigned int *thread_sp; int thread_id; } thread_info_array[MAX_THREADS];
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-23 18:12:02

它不是“第二个结构”。

这一点:

代码语言:javascript
复制
struct thread_info
{
  unsigned int * thread_sp; /* Storage space for thread stack-pointer. */
  int thread_id;            /* Storage space for a thread ID. */
};

是一个类型定义

这一点:

代码语言:javascript
复制
struct thread_info thread_info_array[ MAX_THREADS ];

是MAX_THREADS元素的数组定义,其中每个元素都是上面定义的struct thread_info类型。

票数 2
EN

Stack Overflow用户

发布于 2013-03-23 18:10:39

以下是

代码语言:javascript
复制
struct thread_info thread_info_array[ MAX_THREADS ];

是先前声明的thread_info结构的数组。数组由MAX_THREADS元素组成;如果更改常量,则数组的大小也会更改。

有关需要第二个struct关键字的原因,请参阅C FAQ

票数 2
EN

Stack Overflow用户

发布于 2013-03-23 18:10:59

struct thread_info thread_info_array[ MAX_THREADS ];意味着thread_info_arrayMAX_THREADS元素的thread_info结构的数组。

更改常量只会更改数组中元素的数量,但不会影响struct定义。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15585514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档