Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.
 

Pommie

Well-Known Member
Most Helpful Member
Just installed V2.00 and the later warnings are still there. It's the warnings that involve << (loss of precision) that didn't exist in earlier version.

Mike.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Remember 7 is an int ( constant ) so casting cannot work on a symbolic constant.
XC8 does this thing called "integral promotion" It "tries" to promote to the symbolic constant which I believe
is an unsigned int (16 bit)
 

Pommie

Well-Known Member
Most Helpful Member
Remember 7 is an int ( constant ) so casting cannot work on a symbolic constant.
But uint8_t addr = (PORTC & 7)*2; doesn't give a warning so it's nothing to do with 7 being an int. I even removed the cast. It's something to do with <<. I'm thinking XC8 bug.

Mike.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
If the << is a uint8 into a uint16 there would be no warning but unit8 << unit8 will generate a warning as the WILL be overspill you will lose 7 bits. However! you don't care as you know what you are doing.

In one of my programs i shift both ways as I have a 12bit and a 14 bit mems type sensor.
when I cant get the 12 I need to make the 14bit 12bit so I shift << and >> and it generates 2 warnings.. But I know which bits I want.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
But uint8_t addr = (PORTC & 7)*2; doesn't give a warning so it's nothing to do with 7 being an int. I even removed the cast. It's something to do with <<. I'm thinking XC8 bug.

Mike.
It'd be a bug if didn't work, or if it gave an error, but it's just giving a warning, as it's supposed to - it doesn't like what you're doing :D
 

granddad

Well-Known Member
Most Helpful Member
Am I wrong to ignore XC warnings, that panel is usually full of blue warnings most i don't understand. should i try harder ?
 

Lightium

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.
Your on linux. Read the man page, if there is one.
 

Pommie

Well-Known Member
Most Helpful Member
If the << is a uint8 into a uint16 there would be no warning but unit8 << unit8 will generate a warning as the WILL be overspill you will lose 7 bits.
How is this different when I change the shift to times two?
These two lines do exactly the same thing,
uint8_t addr = (PORTC & 7)<<1;
uint8_t addr = (PORTC & 7)*2;
But the compiler only complains about the first line.

Mike.
 

Pommie

Well-Known Member
Most Helpful Member
I've found a warning level in XC8,
warning.png

But the help file says this can have a value from -9 to 9 but not what the values mean.
Anyone any idea where I'll find an explanation of what these values mean?

Mike.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
How is this different when I change the shift to times two?
These two lines do exactly the same thing,
uint8_t addr = (PORTC & 7)<<1;
uint8_t addr = (PORTC & 7)*2;
But the compiler only complains about the first line.

Mike.
I see what you mean. I don't normally give a rats a*s about trivial warnings, so I just continue.

I would, however, like to see a clean build now and then. LOL no chance with XC8..
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
One thing I have NEVER got... I build for a pic18f26k80. when I load this into the chip it complains there is one too many bytes ?????? MPLABX CREATES THE DAM THING!!

So the linker has issues as well.

BTW.. MPLABIDE 8.XX build nice...
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Just a little info - having long ago got tired of warnings on a fairly 'major' current project, I added:

Code:
// disable unwanted warnings
#pragma warning disable 359
#pragma warning disable 373
#pragma warning disable 520
#pragma warning disable 1510   
#pragma warning disable 2019

This was after getting rid of as many warnings as I could.
 

danadak

Well-Known Member
Most Helpful Member
Just some thoughts about warnings :




Just google "why address compiler warnings", some interesting comments......

If the compiler designer gives you a warning he/she apparently was concerned enough about
compiler behavior that they took the effort to let you know. I think of life support, space applications,
equipment and human safety in designs, so practice of ignoring these wrapped in user not knowing
full extent of the effects of violating a compilers recommended operation is concerning.....


Regards, Dana.
 
Last edited:

Latest threads

New Articles From Microcontroller Tips

Top