简体   繁体   English

请解释此结构用法

[英]Please explain this struct usage

#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 ];

I don't understand the second struct, can you please explain what it does? 我不了解第二个结构,您能解释一下它的作用吗? How does the constant change the struct if we change the constant? 如果我们更改常量,常量将如何更改结构?

Update 更新资料

I think it's the same as: 我认为这与以下内容相同:

struct thread_info { unsigned int *thread_sp; int thread_id; } thread_info_array[MAX_THREADS];

The following 下列

struct thread_info thread_info_array[ MAX_THREADS ];

is an array of the previously declared thread_info structs. 是先前声明的thread_info结构的数组。 The array consists of MAX_THREADS elements; 该数组由MAX_THREADS元素组成; if you change the constant, the size of the array will change. 如果更改常量,则数组的大小将更改。

See the C FAQ for why the second struct keyword is required. 有关为什么需要第二个struct关键字的信息,请参见C FAQ

struct thread_info thread_info_array[ MAX_THREADS ]; implies thread_info_array is an array of thread_info structures of MAX_THREADS elements. 暗示thread_info_arrayMAX_THREADS元素的thread_info结构的数组。

Changing the constant only changes the number of elements in the array but will not impact the struct definition. 更改常量只会更改数组中元素的数量,而不会影响struct定义。

It's not "second struct". 这不是“第二个结构”。

This: 这个:

struct thread_info
{
  unsigned int * thread_sp; /* Storage space for thread stack-pointer. */
  int thread_id;            /* Storage space for a thread ID. */
};

is a type definition . 类型定义

This: 这个:

struct thread_info thread_info_array[ MAX_THREADS ];

is an array definition of MAX_THREADS elements where each element is of type struct thread_info that you've defined above. 是MAX_THREADS元素的数组定义,其中每个元素的类型都是您上面定义的struct thread_info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM