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

warning: (373) implicit signed to unsigned conversion ???

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
Although they are only warnings, I like to go through my code and get rid of them wherever possible. I have the above error in my code and simply don't understand it.
Here is the code concerned,
Code:
void PutNibble(unsigned char nib){
    nib+=0x30;
    if(nib>'9')
        nib+=7;
    PutTXFifo(nib);
}

void PutHex(unsigned char hex){
    PutNibble(hex>>4);                      //Error here
    PutNibble(hex&0x0f);                    //and here
}
The error occurs on the calls to PutNibble. Everything is declared unsigned. So where is the conversion taking place?

Mike.
 

be80be

Well-Known Member
I get them By the bucket load And what get's me is I just trying to learn Mplab X with xc8 and it's there code samples. I did one 2 days ago and the chip can't do the math because there is not enough room in one bank it said and it had 50 warning: (373) implicit signed to unsigned conversion and in the middle it told me the problem was not enough space to do the math.
I ask about this on microchip forum and was digging around and some one said it's bull they just what you to pay for xc8

All of these are in the xc8 files I'm just sending 0 to 5 out the suart
Code:
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:538: warning: (373) implicit signed to unsigned conversion
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:541: warning: (373) implicit signed to unsigned conversion
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:1259: warning: (373) implicit signed to unsigned conversion
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:1305: warning: (373) implicit signed to unsigned conversion
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:1306: warning: (373) implicit signed to unsigned conversion
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:1489: warning: (373) implicit signed to unsigned conversion
/opt/microchip/xc8/v1.42/sources/common/doprnt.c:1524: warning: (373) implicit signed to unsigned conversion
 
Last edited:

be80be

Well-Known Member
This is the first one
Code:
#ifdef    ANYFORMAT
        if(c != '%')
#endif    //ANYFORMAT
The only one I think my code it using is the above but there both unsigned
But I was told I could pay by the month for xc8 or buy it and that gunk all goes away.
Im not to good a C but I'm getting better. Then I got into some boolen code oh my God It messed up my whole ball of wax. I liked to never figured that one out and it was because I had to set path to use some files that xc8 couldn't find and guess what that changed everything when I started a new project.
Code I did it for worked fine but I couldn't even get a blink to build on a new chip.
I found the path reset button and fixed that. I no longer had xc.h show up no matter how I added it.

Maybe now mplab x can use AVR microchip will dump mplab and just use Atmel studio it works great.
Oh this is the code that i was using that made the errors
Code:
void main(void) {
    init_uart();
           
 int i;

for (i = 0; i < 5; i++)
{
        printf("Loop iteration %d\n", i);
}
}
 
Last edited:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Mike! I think the 4 is casting 'hex' to a signed value as constants are signed ( I thought there was a way to treat them as unsigned somewhere )

Just for clarity try casting back.. :- PutNibble((unsigned char)(hex>>4));
 

DerStrom8

Super Moderator
Mike! I think the 4 is casting 'hex' to a signed value as constants are signed ( I thought there was a way to treat them as unsigned somewhere )

Just for clarity try casting back.. :- PutNibble((unsigned char)(hex>>4));
I haven't used XC8 in ages but this was my first instinct as well.
 

Pommie

Well-Known Member
Most Helpful Member
I thought that would be it but no, I've tried both of these and the warning remains,
Code:
    PutNibble((unsigned char)hex>>4);
    PutNibble(hex>>(unsigned char)4);
I'm at a loss.

Edit, I've even tried casting both with
Code:
    PutNibble((uint8)hex>>(uint8)4);
I finally fixed it with
Code:
    PutNibble((uint8)(hex>>4));
Why the first didn't work I have no idea!!
(uint8 = unsigned char)


Mike.
 

Pommie

Well-Known Member
Most Helpful Member
Carrying on the theme of undesirable warnings, I have the following code,
Code:
uint8 OWreadbyte(){
uint8 i,dat;    
    for(i=0;i<8;i++){
        dat>>=1;
        if(OWreadbit())
            dat+=128;
    }    
    return(dat);
}
and I get the warning, warning: (1257) local variable "_dat" is used but never given a value
I know I can just add =0 to the declaration but is there a way to get rid of this warning without generating additional code.
I know I'm being picky but someone might know the answer.

Mike.
 

Mike - K8LH

Well-Known Member
I just tried those two functions in an XC8 v1.35 program in MPLAB 8.92 and it compiled without any warning messages. ???
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
and I get the warning, warning: (1257) local variable "_dat" is used but never given a value
I know I can just add =0 to the declaration but is there a way to get rid of this warning without generating additional code.
I know I'm being picky but someone might know the answer.
I don't know about picky but using uninitialized data is normally a no no.. I know on this occasion the byte is completely written.. The compiler doesn't know that though..
 

Pommie

Well-Known Member
Most Helpful Member
I agree, using uninitialized data is not good. However, in this case I managed to find a way around it.
Code:
uint8 OWreadbyte(){
uint8 i,dat;   
    for(i=0;i<8;i++){
        dat=dat>>1;
        if(OWreadbit())
            dat+=128;
    }   
    return(dat);
}
Even though the code is actually the same, the compiler is happy because dat is given a value - even though it is itself.

Mike.
 

be80be

Well-Known Member
Gee you all good but I told you buy 1.42 and see what happens errors go bye bye haft of them not even your code it xc8 gunk it's not using.

And Mike has a point to I went back to 1.31 and code that on there website compiles not a problem
I install and yes it's 1.43 with mplad 4.00 and the same code went all to hell and the only real answer I got was is it free or did you buy it. I started to give them my debit card but I didn't.
 

Pommie

Well-Known Member
Most Helpful Member
Just switched back to 1.41 and all the silly warnings have gone. Plus, I now have only 1 warning, warning: (343) implicit return at end of non-void function, which is an actual error in my code but was lost among all the nonsense warning. And, weirdly, my code went from 5227 bytes to 5225 - a saving of 2 bytes - wonder what changed between the versions.

Mike.
 

Peteey

New Member
The release notes explain the appearance of the error: http://ww1.microchip.com/downloads/en/DeviceDoc/Readme_XC8.htm
"(XC8E-109) The warning level for warning 373 (implicit signed to unsigned conversion) has been raised from -4 to -3."

Check your project properties to see what warning level you have set for the project. I assume the default is -3 with -9 being the least important level.

I don't expect such a warning. Its seems frivolous. There's not reason to interpret constant positive numbers as signed or unsigned. gcc does not give a warning for the same code with -Wall and -Wextra flags set. The XC32 compiler is based off gcc.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top