• AVR Freaks

Hot!typedef

Author
PK DEY
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/01/20 22:52:04
  • Location: 0
  • Status: offline
2019/02/26 01:15:37 (permalink)
0

typedef

typedef union
{
struct
{
uint8_t full:1;
uint8_t empty:1;
uint8_t reserved:6;
}s;
uint8_t status;
}I2C_TR_QUEUE_STATUS;
The above code is a part of the MCC(1.65) generated code for i2c1 bus. I am feeling difficult with the language used there! What does the bold "typedef" and "1/1/6" says? Could someone explain it for me?
post edited by PK DEY - 2019/02/26 01:18:28
#1

8 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1580
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: typedef 2019/02/26 01:32:14 (permalink)
    +1 (1)
    A copy of any decent C textbook will help, I recommend K&R.
     
    Failing that simple google "typedef"
     
    Come back when you have a question that you cannot answer for yourself.
    #2
    Nikolay_Po
    Super Member
    • Total Posts : 1859
    • Reward points : 0
    • Joined: 2012/04/01 13:49:27
    • Location: Russia, Novorossiysk
    • Status: offline
    Re: typedef 2019/02/26 01:37:20 (permalink)
    0
    Also do google "bit fields". Let I google it for you: https://publications.gbdirect.co.uk//c_book/chapter6/bitfields.html
    Seems to me short and relevant article.
    #3
    Nikolay_Po
    Super Member
    • Total Posts : 1859
    • Reward points : 0
    • Joined: 2012/04/01 13:49:27
    • Location: Russia, Novorossiysk
    • Status: offline
    Re: typedef 2019/02/26 01:37:20 (permalink)
    +1 (1)
    Also do google "bit fields". Let I google it for you: https://publications.gbdirect.co.uk//c_book/chapter6/bitfields.html
    Seems to me short and relevant article.
    #4
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: typedef 2019/02/26 01:39:09 (permalink)
    0
    PK DEY
    ...
    What does the bold "typedef" and "1/1/6" says? Could someone explain it for me?

    Bold does not work inside code blocks.
    As crosland mentions, "typedef" will be covered in ANY C textbook. You hjave to make SOME effort yourself.
    the 1/1/6 are "bitfields", and are a feature of the "union" structure. Again, this will be mentioned in every C textbook.
     

    Nearly there...
    #5
    rodims
    Super Member
    • Total Posts : 1479
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: typedef 2019/02/26 01:40:23 (permalink)
    0
    You should decide whether you feel difficult with
    structures
    or
    unions
    or
    typedefs
    or
    bitfields
     
    I had the impression you only lack experience with bitfields, which you can google of course:
    https://www.tutorialspoin...mming/c_bit_fields.htm
    #6
    mbrowning
    Just a Member
    • Total Posts : 1370
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: typedef 2019/02/26 04:57:44 (permalink)
    0
    qhb
    Bold does not work inside code blocks
    it seems to display fine on the mobile version, at least on my phone.

    Oh well - there's always next year
    #7
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: typedef 2019/02/26 05:40:06 (permalink)
    0
    mbrowning
    qhb
    Bold does not work inside code blocks
    it seems to display fine on the mobile version, at least on my phone.
    Agree. The mobile theme displays the bolding inside a code block, the standard desktop theme does not.

    Nearly there...
    #8
    Mysil
    Super Member
    • Total Posts : 3325
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: typedef 2019/02/26 07:20:50 (permalink)
    0
    Hi,
    All the XC...  compilers make use of similar typedef's with union of struct declarations, 
    in the device support files:  <xc.h>
    to help pick apart the various fields and bits in SFR control registers.
     
    All the:   LATCbits.LATC2 = 1;  and similar constructs are based on such typedef declarations.
     
        Mysil
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5