• C

Question with regard to Volatile type specifier!

Hi experts,

I'm just wondering what a volatile type specifier really does?  Is it essential in programming synchronization problem?


Who is Participating?

Improve company productivity with a Business Account.Sign Up

sunnycoderConnect With a Mentor Commented:
check this link
R6Author Commented:
hi sunnycoder & ankuratvb,

thanks for helping me out!

heres my actual problem:

volatile struct can *theCan;

void *aFunc() {
  return theCan;

and the compiler signals a warning that says "warning: return discards qualifiers from pointer target type"

what does that really mean?

thank u!


Firewall Management 201 with Professor Wool

In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!

brad_1Connect With a Mentor Commented:
You declared the return type as a "void *"  and returned a "struct can *". The mismatch between these causes the compiler to issue a warning. Either change the return type to "struct can *", or cast the returned pointer to "void *".
e.g. return (void *) theCan;

I don't know if the volatile keyword is relevant to the return type.

Does the warning disappear if you remove the volatile from thecan's declaration.?

I cant test it myself coz on my compiler,i dont even get a warning.

BTW,what compiler are u using?

It shouldnt be because of the void * return type and you returning a struct can *
coz void pointers can be assigned to any kind of pointer without requiring an explicit cast and without loss of information.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.