• AVR Freaks

Hot!mcc generated error

Page: 12 > Showing page 1 of 2
Author
northeastman
Senior Member
  • Total Posts : 132
  • Reward points : 0
  • Joined: 2009/11/07 05:49:38
  • Location: North East England
  • Status: offline
2019/11/11 07:43:11 (permalink)
0

mcc generated error

Hi 
I am running XC8 V2.10 C90 and generating code for a PIC18F47K40, using a Windows 10 64 bit machine.
 
Using mcc 3.85.1 we have generated a module for EUSART1 for the chip.
 
This code in the mcc module produces:
mcc_generated_files/eusart1.c:125:32: warning: (373) implicit signed to unsigned conversion
 
bool EUSART1_is_rx_ready(void) {
       return (eusart1RxCount ? true : false);
}
 
Changing the code to:
bool EUSART1_is_rx_ready(void) {
   (bool)return (eusart1RxCount ? true : false);
}
Obviously, eliminates the error.
 
Question is why does code generated by mcc generate these errors, or is this a bug in the XC8 V2.10 compiler?
 
Thanks for reading

Regards
Northeastman
#1

20 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6376
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: mcc generated error 2019/11/11 07:51:24 (permalink)
    +2 (4)
    This is a "warning" not an error Smile: Smile
    #2
    northeastman
    Senior Member
    • Total Posts : 132
    • Reward points : 0
    • Joined: 2009/11/07 05:49:38
    • Location: North East England
    • Status: offline
    Re: mcc generated error 2019/11/11 08:02:45 (permalink)
    0
    OK Jim but its still annoying

    Regards
    Northeastman
    #3
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/11 08:16:37 (permalink)
    0
    That warning is a result of "true" and "false" being defined as signed integers while "bool" is an unsigned char type, defined in the <stdbool.h> header file.
    #4
    Jim Nickerson
    User 452
    • Total Posts : 6376
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: mcc generated error 2019/11/11 08:16:42 (permalink)
    0
    how is eusart1RxCount declared ?
    #5
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/11 08:18:41 (permalink)
    +1 (1)
    JANickerson
    how is eusart1RxCount declared ?

    Nothing to do with the warning. ;)
     
    #6
    northeastman
    Senior Member
    • Total Posts : 132
    • Reward points : 0
    • Joined: 2009/11/07 05:49:38
    • Location: North East England
    • Status: offline
    Re: mcc generated error 2019/11/11 08:31:21 (permalink)
    0
    Hi,
    so why should true and false be defined as unsigned char, when they can only be a bool 1 or 0?
     
    Maybe its a language thing, if so then eusart1RxCount should return an unsigned char and not a bool and the fault is with mcc?
     
    Any illuminating thoughts on that one?

    Regards
    Northeastman
    #7
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/11 08:34:52 (permalink)
    +1 (1)
    Here's <stdbool.h> supplied with XC8:
    #ifndef __bool_true_and_false_are_defined
    #define __bool_true_and_false_are_defined
     
    typedef unsigned char bool;
     
    #define true 1
    #define false 0
    #endif

    To get rid of that warning, it would have to be:

    #define true 1u
    #define false 0u

     
    #8
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/11 08:39:13 (permalink)
    +1 (1)
    northeastman
    Maybe its a language thing, if so then eusart1RxCount should return an unsigned char and not a bool and the fault is with mcc?
     
    Any illuminating thoughts on that one?

    As I said, eusart1RxCount has nothing to do with this warning -- it is just a condition.  What returns from the conditional operator is its second or third operand, and in this case it is assigned to a bool type.
    #9
    northeastman
    Senior Member
    • Total Posts : 132
    • Reward points : 0
    • Joined: 2009/11/07 05:49:38
    • Location: North East England
    • Status: offline
    Re: mcc generated error 2019/11/11 11:17:00 (permalink)
    0
    Hi,
    so what you appear to be saying is that <stdbool .h> supplied with XC8 is the source of the warning and not mcc?
     
    Will this get fixed maybe in a future release?
     
    I only used eusart1RxCount as the example, but be aware that there are other similar constructs employed by mcc.
     
    I know I can get rid of the warning by modifying the associated mcc file, (as in my first post), but each time I use mcc I will need to either change the file by hand again, or go through the merge process.
     
    Thanks to everyone for their inputs.
    post edited by northeastman - 2019/11/11 11:18:31

    Regards
    Northeastman
    #10
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11432
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: mcc generated error 2019/11/11 11:49:46 (permalink)
    +3 (3)
    The C standard requires "true" and "false" to be signed, but it doesn't specify whether bool is signed.  The standard does permit you to #undef bool, true, and false, and create your own macros. 
    #ifdef __bool_true_false_are_defined
    #undef bool
    #undef true
    #undef false

    #define bool unsigned char
    #define true 1U
    #define false 0U
    #endif

    #11
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/11 13:13:37 (permalink)
    +1 (1)
    jtemples
    The C standard requires "true" and "false" to be signed, but it doesn't specify whether bool is signed.  The standard does permit you to #undef bool, true, and false, and create your own macros. 
    #ifdef __bool_true_false_are_defined
    #undef bool
    #undef true
    #undef false

    #define bool unsigned char
    #define true 1U
    #define false 0U
    #endif


    Nice!  That is
    #ifdef __bool_true_and_false_are_defined

    #12
    northeastman
    Senior Member
    • Total Posts : 132
    • Reward points : 0
    • Joined: 2009/11/07 05:49:38
    • Location: North East England
    • Status: offline
    Re: mcc generated error 2019/11/12 01:23:04 (permalink)
    +1 (1)
    HI all,
    thanks for your responses.
     
    We are using 1and0's solution and redefining bool, true and false.
     
    A simple but effective solutiongrin: grin

    Regards
    Northeastman
    #13
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: mcc generated error 2019/11/12 01:28:47 (permalink)
    0
    Actually, it was jtemple's solution, 1and0 just corrected a typo. :)
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #14
    Maldus
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2016/08/17 09:55:57
    • Location: 0
    • Status: offline
    Re: mcc generated error 2019/11/12 01:53:02 (permalink)
    -1 (1)

    This is a "warning" not an error Smile:

    If this is a joke it is not funny. PIC microcontrollers and MCC are supposed to be professional products, not toys. Unfortunately this "good enough" attitude seems a stable in Microchip's philosophy.
    #15
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: mcc generated error 2019/11/12 02:15:40 (permalink)
    +4 (6)
    You are aware that no-one responding here is a Microchip employee? We're all just users.
    Jim was making the valid point that there is a big difference between an error and a warning.
    An "error" means there IS something wrong.
    A "warning" just indicates that there might be a problem.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    Jim Nickerson
    User 452
    • Total Posts : 6376
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: mcc generated error 2019/11/12 08:48:52 (permalink)
    0
    ric,
    thank you for your kind words.
     
    #17
    Jim Nickerson
    User 452
    • Total Posts : 6376
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: mcc generated error 2019/11/12 08:52:35 (permalink)
    +1 (1)
    Maldus

    This is a "warning" not an error Smile:

    If this is a joke it is not funny. PIC microcontrollers and MCC are supposed to be professional products, not toys. Unfortunately this "good enough" attitude seems a stable in Microchip's philosophy.


    A thumbs down for stating a simple fact ?
    English comprehension ?
    #18
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/12 10:09:05 (permalink)
    0
    ric
    ... just corrected a typo. :)

    Actually, jtemple uses the standard macro, and it's XC8 that makes the typo. ;)
     
    From the C99 Standard §7.16:
     
    The header <stdbool.h> defines four macros.
     
    bool
          expands to _Bool.
    true
          which expands to the integer constant 1,
    false
          which expands to the integer constant 0, and
    __bool_true_false_are_defined
          which expands to the integer constant 1.
     
    ... a program may undefine and perhaps then redefine the macros bool, true, and false.
    #19
    1and0
    Access is Denied
    • Total Posts : 10005
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: mcc generated error 2019/11/12 10:14:27 (permalink)
    +1 (1)
    jtemples
    The C standard requires "true" and "false" to be signed, but it doesn't specify whether bool is signed.  The standard does permit you to #undef bool, true, and false, and create your own macros. 

     
    From the language standard:
    C99 §6.2.5
    An object declared as type _Bool is large enough to store the values 0 and 1.
     
    The type _Bool and the unsigned integer types that correspond to the standard signed integer types are the standard unsigned integer types.

    So,
    • The _Bool type is a new type appearing in the C99 standard.
    • It is an unsigned integer type.
    • Its range of values has to be able to hold the values 0 and 1.
    • The range of values of _Bool is contained in the range of values of any other unsigned integer type.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5