AnsweredAssumed Answered

General C question - volatile cast

Question asked by bonelli on Nov 30, 2015
Latest reply on Dec 1, 2015 by AvaTar

Using a lot of global variables modified into ISR sections, I use a lot the "volatile" keyword when needed.

volatile int foo;

int square(int din)
   return din*din;

result = square(foo); // Does not compile: cast error

Actually, this kind of C-code are not supported by IAR:
"int" type is not compatible with "volatile int" type.

The obvious solution is to do a cast:
result = square((int)foo); // Compile very well but absolutely boring!

With big projects, many structures and many functions with many parameters doing a cast for each parameter is very time-consuming and does not render the code very clear.

Is there a way to tell to the compiler: "Don't annoy me with volatile uncasted types!" ?

Thank you