• AVR Freaks

Hot!xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int

Author
Santiago Marino
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2018/09/24 15:40:29
  • Location: 0
  • Status: offline
2019/04/21 13:25:39 (permalink)
0

xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int

Hi, I'm working with the following tools:
MPLAB 5.15
xc8 2.05
C99
PIC18F47K42

I'm trying to build a UNION:
typedef union {
struct {
__uint24 typeFile:3;
__uint24 idFile:21;
}regs;
}entry_id_typefile

But it seems that the 24bit data type is not supported.

error: bit-field 'typeFile' has bad bitfield type '__uint24' (aka 'unsigned __int24')

Replace __uint24 -> unsigned short long, but.. ERROR:

error: cannot combine with previous 'short' declaration specifier

I have read several articles on the Internet but in all these articles it seems that they are only conjectures, opinions or assumptions, but nothing concrete.
Any suggestions on how to create a structure of this type?
post edited by Santiago Marino - 2019/04/21 13:27:08
#1

7 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/21 13:46:21 (permalink)
    +2 (2)
    The XC8 User manual explains all this. Read that, not "the Internet".
    The variables should all be type "int", not "__uint24"
    Each individual field can not be more than 8 bits wide.
    These details are "compiler specific" in the C standard, which is why you need to read the manual that comes with your particular compiler, not a generic C guide which is probably written for PC compilers.
     
     

    Nearly there...
    #2
    Mysil
    Super Member
    • Total Posts : 3324
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/21 15:17:58 (permalink)
    +3 (3)
    Hi,
    In XC8, making code to run on microcontroller that can process only 8 bits in each instruction,
    a bitfield with more than 8 bits, is not supported.
    Likewise, a bitfield is not allowed to span from one byte into the next byte.
    You may make an array of 3 bytes a part of the struct,
    or a 24 bit unsigned integer, that is not a bitfield.
    If you really want exactly the structure indicated in message #1,
    you will have to make 3 + 5 + 8 + 8 bits,
    and there is no point in making any part of the struct with a bitfield type larger than uint8_t .
     
    It may be done like this:
    typedef union 
    {    struct
        {   uint8_t typeFile:3;
            uint8_t idFileL :5;
            uint8_t idFileM :8;
            uint8_t    idFileU :8;
        }regs;
        struct
        {   __uint24 idFileW;
        };        
    } entry_id_typefile;  

    Setting the following values:
        typefile.regs.typeFile = 7;
        typefile.regs.idFileL  = 4;
        typefile.regs.idFileM  = 8;
        typefile.regs.idFileU  = 16;

    give: typefile.idFileW    0x100827
     
        Mysil
    #3
    Santiago Marino
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2018/09/24 15:40:29
    • Location: 0
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/21 16:49:17 (permalink)
    0

    You have been very clear, your simple explanation has clarified in a few lines what I have not seen in many internet pages
    Thanks!!!!!!!!
    #4
    mlp
    boots too small
    • Total Posts : 749
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/22 12:04:57 (permalink)
    +1 (1)
    qhb
    The XC8 User manual explains all this. Read that, not "the Internet".
    The variables should all be type "int", not "__uint24"

    Almost.
    The base type of a bitfield should be either int or unsigned int.
    This is in the C standard and has been there for nearly 3 decades.

    The maximum width of a bitfield is Implementation Defined, which means that the compiler documentation must tell you what it is and different compilers are allowed to tell you different things.

    Mark (this opinion available for hire)
    #5
    1and0
    Access is Denied
    • Total Posts : 9231
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/22 12:24:07 (permalink)
    0
    mark.pappin
    The base type of a bitfield should be either int or unsigned int.
    This is in the C standard and has been there for nearly 3 decades.

    IIRC, XC8 does not support signed bitfield.
    #6
    Mysil
    Super Member
    • Total Posts : 3324
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/22 13:08:53 (permalink)
    0
    Hi,
    Extending the experiment from message #3:
    typedef union 
    {    struct
        {   uint8_t typeFile:3;
            uint8_t idFileL :5;
            uint8_t idFileM :8;
             int8_t    idFileU :8;
        }regs;
        struct
        {   __int24 idFileS;
        };        
        struct
        {   __uint24 idFileW;
        };        
    } entry_id_typefile;  

    XC8 complain:
    In file included from I2C_Callback.c:69:
    ./I2C_Callback.h:12:17: warning: bit-field 'idFileU' has signed type; signed bitfields are not supported 

    Running code with these values:
        typefile.regs.typeFile = 7;            /* Typefile bitfield experiment. */
        typefile.regs.idFileL  = 4;
        typefile.regs.idFileM  = 8;
        typefile.regs.idFileU  = -16; 

    Debugger show these values:
    typeFile  unsigned char        0x07    7
    idFileL    unsigned char        0x04    4
    idFileM    unsigned char       0x08    8
    idFileU    unsigned char        0xF0    240
    idFileS    short long              0xF00827    -1046489
    idFileW    unsigned short long   0xF00827   15730727
     
        Mysil
    #7
    mlp
    boots too small
    • Total Posts : 749
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: xc8 2.05 error: bit-field has bad bitfield type '__uint24' (aka 'unsigned __int 2019/04/24 06:12:09 (permalink)
    0
    Mysil
    Extending the experiment from message #3:

    but ignoring the point of my comment #5, rendering the experiment pointless.
     

    Mark (this opinion available for hire)
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5