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?
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!


Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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.

All Courses

From novice to tech pro — start learning today.