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

thanks

r6
R6Asked:
Who is Participating?
 
sunnycoderCommented:
check this link
http:Q_20684549.html
0
 
ankuratvbCommented:
0
 
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!

r6



0
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_1Commented:
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.

Brad
0
 
ankuratvbCommented:
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?

0
 
ankuratvbCommented:
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.

0
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.