预选赛被丢弃在结构指针上
当我声明
typedef struct myStruct
{
//Some attributes
}myStruct_t, *pMyStruct_t;
void func(myStruct_t* someStruct);
一个结构指针如下并将其传递给功能时,我的结构和函数如下所示,一切都很好,
volatile pMyStruct_t pStruct;
但是当我以这种方式声明指针时,我会发现挥发性预选赛在功能中丢弃的错误,
volatile myStruct_t* pStruct;
我猜我问题是第一个方法是如何工作的,没有提出预选错误错误?声明psstruct
变量的两种方式有什么区别?
I have struct and function declared as follows
typedef struct myStruct
{
//Some attributes
}myStruct_t, *pMyStruct_t;
void func(myStruct_t* someStruct);
When I declare a struct pointer as follows and pass it to the function, all is fine
volatile pMyStruct_t pStruct;
But when I declare the pointer this way I get an error that the volatile qualifier is discarded in the function
volatile myStruct_t* pStruct;
I guess my question is how come the first method works and no qualifier errors are raised? What is the difference between the two ways the pStruct
variable is declared?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此代码等同于此:
与此相差有所不同:
其中的差异,哪个变量将是波动的。
在第一种情况下,指向结构本身的指针将是挥发性的。
在第二种情况下,结构对象将是挥发性的,而不是指针。
在我看来,第二选择是您的。无论如何,使指针波动几乎没有意义。
您可以用挥发性关键字指针:
但是在这种情况下,struct将始终是挥发性的,我不知道这对您来说是可以接受的。
This code equivalent to this:
There is a difference with this:
Difference in that, which variable will be volatile.
In first case, pointer to the struct itself will be volatile.
In second case, struct object will be volatile, not pointer.
It seems to me, that second choice is yours. Any way, there is little sense to make pointer volatile.
You can
typedef
pointer with the volatile keyword:But in this case, struct will always be volatile, I don't know is this acceptable for you.
这些声明
是
不同的。
第一个表示以下
是第一个声明中的以下内容,是指指针本身是挥发性的,而在第二个声明中,指针本身并不挥发。
您可以使用挥发性指针的值初始化功能参数。但是您可能不会丢弃尖头对象的预选赛
These declarations
and
are different.
The first one means the following
That is in the first declaration it is the pointer itself that is volatile while in the second declaration the pointer itself is not volatile.
You may initialize the function parameter with a value of a pointer that is itself is volatile. But you may not discard the qualifier for the pointed object
第一个
创建
volatile
变量ps struct
通过复制传递给您的函数。指向的内存不是
挥发性
。第二个
定义指向
volatile
内存的指针。这些非常不同。
这也表明了为什么将指针类型隐藏到
typedef
中是一个可怕的想法。The first one
Creates a
volatile
variablepstruct
that is passed by copy to your function.The memory where it points to is not
volatile
.The second one
defines a pointer to a
volatile
memory.These are very different.
This also shows why it is widely regarded to be a terrible idea to hide a pointer type into a
typedef
.