Continue to Site

# How do I get rid of this warning?

#### Pommie

##### Well-Known 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
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.

#### Nigel Goodwin

##### Super Moderator
I don't know if it will help or not?, but which mode are you using the compiler in?, C90 or C99 - if you're using C99 it 'might' be that it could be the reason (so try C90).

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
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
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
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
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

##### Well-Known 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 ?

#### Nigel Goodwin

##### Super Moderator
Am I wrong to ignore XC warnings, that panel is usually full of blue warnings most i don't understand. should i try harder ?
I would suggest that you don't get too carried away about them They are just warnings, and don't mean things won't work perfectly.

#### 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.

#### Pommie

##### Well-Known 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
I was more concerned about finding older versions of XC8.

Mike.

#### Lightium

##### Member
Is this any good:

#### Pommie

##### Well-Known Member
I've found a warning level in XC8,

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.

#### Pommie

##### Well-Known Member
Is this any good:
Thanks, luckily, I found that yesterday and installed V2.00.

Mike.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
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
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
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.

##### Well-Known Member
Just some thoughts about warnings :

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:

Replies
3
Views
7K
Replies
6
Views
1K
Replies
1
Views
841
Replies
5
Views
372
Replies
9
Views
889