This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why no volatile variables for H/W status BUT works ?

I was taught if the variable might be changed by OS,hardware, or interrupt routine asynchronous it must be declared as "volatile" !

But reviewing current code base I found no "volatile" variables for H/W but it works well...

My question is: besides using "volatile" variable is there any way to access peripheral device mapped to XDATA ?

Parents
  • "I was taught if the variable might be changed by OS,hardware, or interrupt routine asynchronous it must be declared as 'volatile' !"

    I think you've slightly misinterpreted what you were taught...

    A more precise statement would be, "without the volatile qualifier, bad things may happen due to optimisation"

    "But reviewing current code base I found no 'volatile' variables for H/W but it works well..."

    This means one of two things:

    1: The original author thought about this carefully and concluded that, in this particular case, the 'voltile' qualifier was not needed;

    2: You are just very lucky!

Reply
  • "I was taught if the variable might be changed by OS,hardware, or interrupt routine asynchronous it must be declared as 'volatile' !"

    I think you've slightly misinterpreted what you were taught...

    A more precise statement would be, "without the volatile qualifier, bad things may happen due to optimisation"

    "But reviewing current code base I found no 'volatile' variables for H/W but it works well..."

    This means one of two things:

    1: The original author thought about this carefully and concluded that, in this particular case, the 'voltile' qualifier was not needed;

    2: You are just very lucky!

Children