与语法,结构混淆 [英] confused with syntax, structures

查看:89
本文介绍了与语法,结构混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下语法感到困惑,但我读了一下它,我认为它是有效的:



I was confused with following syntax, but that I read a bit about it, I think it is valid:

typedef struct t_config
{
	u16_t   x;  
	u16_t   y; 
	u16_t   z_pdp;
} t_config, *pt_config; // What is *pt_config?? Is it a pointer? Or a type?

 
void profile_append(pt_config conf); // If what is written above is a variable, then what is pt_config??? It is written as a type here

推荐答案

这个定义意味着t_config是一个结构,而pt_config是一个指针那个结构。



以下是等效的声明:

This definition means that t_config is a struct, and pt_config is a pointer to that struct.

The following are equivalent declarations:
void profile_append(pt_config conf);
void profile_append(t_config conf*);


int p;      // p is variable of int type
int *pNo;  // pNo is a pointer variable which will point to int type





类似的方式* pt_config表示指向t_config类型的指针,即结构,即用户定义数据类型



In similar ways *pt_config means pointer to t_config type which is structure i.e. user define data type


因为它是用typedef定义的,所以 pt_config 是一个类型定义。可以把它想象成

As it is defined with a typedef, pt_config is a type definition. Think of it as
typdef   struct t_config*   pt_config;



从现在开始,您可以在所有需要类型的地方使用 pt_config ,例如在函数参数列表中:


From now on you can use pt_config in all places where a type is expected, for example in a function argument list:

void profile_append(pt_config conf);



以上声明与:


The above declaration is the same as:

void profile_append(struct t_config* conf);


这篇关于与语法,结构混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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