Topic : How to activate compiler warnings in case of implicit conversions

Forum : ST7/STM8

Original Post
Post Information Post
June 10, 2010 - 4:28pm
Guest

Hi,

is it possible to generate a compiler warning if an implicit conversion or typecast (promotion/demotion) is performed?

Simple example:

#pragma WARNINGLEVEL(2)

void main(){
   volatile unsigned int uiVar = 65535;   //16bit variable // volatile to suppress optimizing
   volatile unsigned char ucVar = 3;      //8 bit variable // volatile to suppress optimizing
   
   for(;;){
      ucVar++;
      uiVar--;
      
      ucVar = uiVar;   //Unintentional assignment of a 16bit value to a 8bit variable
                       //I'd like to be informed that the MSbyte will be cut off.
      
      ucVar++;
      uiVar--;
      
      ucVar =(unsigned char) uiVar;   //I really want to assign a 16bit value to a 8bit variable
                                      //and I know that the MSbyte will be cut off.
   }
}

Of course with standard compiler-settings no warning should appear, since demotion is part of C. But what if I made a mistake (shame on me) and assigned a 16bit value to a 8bit variable? I'd be glad if I could apply a compiler directive, to find more lines probably being responsible for errors.

The gcc C-compiler has the "-Wconversion" flag. Is there something similar with the RCSTM8?

Thanks,
DanZ

Replies
Post Information Post
+1
0
-1
June 14, 2010 - 11:25am
Raisonance Support Team

Hi DanZ,

This is a good input. We'll add this feature in the compiler, but this will not be in the next release (which is already under validation phase).

Regards,
Bruno