cancel
Showing results for 
Search instead for 
Did you mean: 

General C question - volatile cast

tarzan2
Associate II
Posted on November 30, 2015 at 19:31

Hello,

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

#volatile-cast-type
2 REPLIES 2
clark2
Associate II
Posted on November 30, 2015 at 22:29

You should not need to typecast since the ''volatile'' is only a type qualifier.

You show no declaration of ''result''.

I tried similar code in CrossStudio, which uses the GCC compiler, and it works fine.

Perhaps you should be asking the folks at IAR about this?

AvaTar
Lead
Posted on December 01, 2015 at 09:00

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

 

I don't know the IAR ARM compiler in detail, but that is probably not the full truth.

Gcc has an option ''

-Werror

'' which makes all warnings to errors. The IAR compiler surely has something similiar, and you, or the project creation wizard, have set it.

With gcc, you can set ''

-Wall

'' (and ''

-Wextra

'') instead to be informed about such issues, without failing the build.