1. 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.
    Dismiss Notice

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

Discussion in 'Microcontrollers' started by Pommie, Aug 16, 2017.

  1. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,151
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    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 (text):

    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.
     
  2. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    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 (text):

    /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: Aug 16, 2017
  3. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    This is the first one
    Code (text):

    #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 (text):

    void main(void) {
        init_uart();
               
     int i;

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

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK

    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));
     
    • Agree Agree x 2
  6. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,512
    Likes:
    507
    Location:
    Vermont (GMT-5:00)
    I haven't used XC8 in ages but this was my first instinct as well.
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,151
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    I thought that would be it but no, I've tried both of these and the warning remains,
    Code (text):

        PutNibble((unsigned char)hex>>4);
        PutNibble(hex>>(unsigned char)4);
     
    I'm at a loss.

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


    Mike.
     
  8. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,151
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    Carrying on the theme of undesirable warnings, I have the following code,
    Code (text):

    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.
     
  9. Mike - K8LH

    Mike - K8LH Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    3,642
    Likes:
    109
    Location:
    Michigan, USA
    I just tried those two functions in an XC8 v1.35 program in MPLAB 8.92 and it compiled without any warning messages. ???
     
  10. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,151
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    Hi Mike,

    What did you try? I'm using MPLAB.X and CX8 V1.42.

    Mike.
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK
    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..
     
  12. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,151
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    I agree, using uninitialized data is not good. However, in this case I managed to find a way around it.
    Code (text):

    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.
     
  13. Mike - K8LH

    Mike - K8LH Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    3,642
    Likes:
    109
    Location:
    Michigan, USA
    I tried the PutNibble() and PutHex() functions (MPLAB 8.92, XC8 1.35)... No warning messages...
     
  14. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    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.
     
  15. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,151
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    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.
     
  16. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK
    Remind me to stay with v1.41 for the immediate future...
     
  17. Peteey

    Peteey New Member

    Joined:
    Nov 22, 2017
    Messages:
    1
    Likes:
    0
    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.
     

Share This Page