[英]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 ];
我不了解第二個結構,您能解釋一下它的作用嗎? 如果我們更改常量,常量將如何更改結構?
我認為這與以下內容相同:
struct thread_info { unsigned int *thread_sp; int thread_id; } thread_info_array[MAX_THREADS];
下列
struct thread_info thread_info_array[ MAX_THREADS ];
是先前聲明的thread_info
結構的數組。 該數組由MAX_THREADS
元素組成; 如果更改常量,則數組的大小將更改。
有關為什么需要第二個struct
關鍵字的信息,請參見C FAQ 。
struct thread_info thread_info_array[ MAX_THREADS ];
暗示thread_info_array
是MAX_THREADS
元素的thread_info
結構的數組。
更改常量只會更改數組中元素的數量,而不會影響struct
定義。
這不是“第二個結構”。
這個:
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 ];
是MAX_THREADS元素的數組定義,其中每個元素的類型都是您上面定義的struct thread_info
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.