This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Warning[Pe069]: integer conversion resulted in truncation

Hi Folks,

This is my 1st post here so treat me gently! I'm finishing a project, and want to eliminate all warnings & errors from the build in IAR workbench. It persistently gives the warning:

Warning[Pe069]: integer conversion resulted in truncation

There was a thread recently on this, but my cause looks different to that. The offending line is:

  P1DIR =  activate_sounder + data_out_yled + batt_load + snd_tem;

If one of the definitions is removed from the list, the warning goes. The program as a whole works very well, but having an unexplained warning bothers me.

Defines are:

#define opt_adc   0x01
#define data_in   0x02
#define data_out_yled  0x04 
#define batt_load  0x10  
#define snd_300khz  0x08 
#define batt_adc  0x20   
#define heat_adc  0x40
#define activate_sounder  0x80

Simple stuff... there are PxDIR statements for other ports but only this one gives a warning. Can anyone else drop those lines in a see if the same result happens?

Thanks,

Rob.

 

  • I'm missing the snd_tem define.

    Anyway, what you could try is to use an u after each define, so 0x80u for example. Or you can try and use oring instead of adding (use | instead of +).

    Generally I advise to use as little #defines as possible, for this you could also use constant values like:

    const uint8_t  opt_adc = 0x01u;

    This will help you as you will get compiler warnings and errors on type mismatch and other bad things which can happen using defines. Generally the compiler will replace the occurrences with the const value, so there is no overhead compared to using #defines.

  • Thanks Bernhard,

    Using the | operator solves it. The snd_tem got missed off as it is in the next block of defines. I will use "const uint8_t" in the next project. Integer conversion resulted in trucation is a typically opaque error message for a compiler!

    Previously I have worked on Microchip MPLAB for 5 years, and still in the process of learning the oddities of something else.

    Regards,

    Rob.

**Attention** This is a public forum