Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Qualifier is discarded on struct pointer

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

These declarations

volatile pMyStruct_t pStruct;

and

volatile myStruct_t* pStruct;

are different.

The first one means the following

myStruct_t* volatile  pStruct;

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading