How do I get rid of this warning?

Pommie

Well-Known Member
Most Helpful Member
I've got an MPLABX project and the latest version of the compiler seems to have gone insane with warnings,
Code:
main.c:97:40: warning: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Wconversion]
    uint8_t addr = (PORTC & (uint8_t)7)<<(uint8_t)1;
            ~~~~   ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
I've cast everything I can think of and it's still all over my code.
Where is the conversion?
What is the Error number so I can disable it?

If I change it to, uint8_t addr = (PORTC & 7)*2; then no warning is given - even though it's going from 9 bit to 8 bit (I know it isn't really).
It seems to occur whenever << is used such as uint8_t temp=1<<pin;

I like to have my code error free so I can instantly see if a new error (or warning) has appeared.
However, XC8 is now warning me about stuff in library calls,
Code:
/opt/microchip/xc8/v2.41/pic/sources/c99/common/Umul8.c:4:: advisory: (1510) non-reentrant function "___bmul" appears in multiple call graphs and has been duplicated by the compiler

This is only an Advisory and I have a number, 1510 so I can use #pragma warning disable 1510 - yes, it's a warning.

The older versions of XC8 didn't do this - maybe I need to look for an archive. I'm using a new install on Linux hence the newer XC8.

How do I install old compilers in Linux?

Mike.
 
I hate and try to get rid of any warnings in my code so I instantly see if a new one appears - you never know I may have inadvertently put if(x=1) etc. and I want those warnings. I can of course instantly fix it by changing to if(x==1). However, warnings like addr=(PORTC&7)<<1; are just wrong. And no amount of casting gets rid of them.

JUST WRONG, WRONG, WRONG.

And, microchip should be fixing these obvious bugs - which they don't.

It might not be a major concern but when I can't see the wood (real errors) for the trees (Microchip imagined errors) then it is a concern.

Mike.
And, where is that list of error levels?
 
I hate and try to get rid of any warnings in my code so I instantly see if a new one appears - you never know I may have inadvertently put if(x=1) etc. and I want those warnings.
And, where is that list of error levels?

Do you get a warning for that?, I don't recall ever seeing one? - it's a perfectly valid and correct statement, it just doesn't do what you intended - apparently it's better to use (1==x) as if you put (1=x) by mistake, it gives an error. However, I must admit, I never do

I can't remember where I got the list of warnings from?, other than it involved google

It might even have been one warning at a time?, rather than a list.
 
This is the warning you get if you accidentally put if(x=1) etc.
Code:
main.c:91:14: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
    if(CCP2IF=1){
       ~~~~~~^~
Again, no warning number but it does tell you how to silence the warning,
main.c:91:14: note: place parentheses around the assignment to silence this warning


Mike.
 
I've just tried, where days is an unsigned int:

C:
if(days=1)
{
    
}

And it gives the warning:

Code:
main.c:588: warning: (758) constant conditional branch: possible use of "=" instead of "=="

I can't say I've ever noticed it before though?.

Rather strangely, if I try:

C:
if(CCP2IF=1)
{
    
}

It doesn't give a warning at all?
 
We seem to have two different sets of warnings but yours at least has a warning number.

Just tried various versions of if(CCP1IF=1) and always get the warning.

I also get a "note" (not sure what a "note" is except a warning with a different name!!!)
Code:
main.c:91:14: note: use '==' to turn this assignment into an equality comparison

It's another Microchip mystery.

Mike.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…