Thread: typedef struct

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    31

    typedef struct

    Hi everyone,

    I came across with this chunk of code

    Code:
    struct ble_blink_s {
      uint16_t service_handler;
      uint8_t service_type;
    };
    
    typedef struct ble_blink_s ble_blink_t;
    Can I re-write the above code like this?

    Code:
    typedef struct ble_blink_s {
      uint16_t service_handler;
      uint8_t service_type;
    } ble_blink_t;
    Thanks in advance
    Nick
    Last edited by Salem; 03-31-2020 at 08:58 AM. Reason: removed crayola

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,970
    Yes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    31
    Thanks for your ptompt answer!!

    Also, these syntax are equivalent?

    Code:
    typedef struct{
        ble_cus_evt_type_t evt_type;                                  
    } ble_cus_evt_t;
    Code:
    typedef struct ble_cus_evt_t{
        ble_cus_evt_type_t evt_type; 
    };

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,970
    No..
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2019
    Posts
    31
    Quote Originally Posted by Salem View Post
    No..
    Could you explain?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,970
    What's to explain?

    The second one just doesn't compile.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Feb 2019
    Posts
    31
    Thanks Salem!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. typedef struct vs struct declaration error in code
    By shaswat in forum C Programming
    Replies: 3
    Last Post: 07-25-2016, 06:45 AM
  2. differences between struct and typedef struct
    By stanlvw in forum C Programming
    Replies: 1
    Last Post: 07-22-2008, 03:28 PM
  3. typedef struct ?
    By audinue in forum C Programming
    Replies: 8
    Last Post: 06-22-2008, 11:55 AM
  4. Typedef and Struct
    By tikelele in forum C Programming
    Replies: 11
    Last Post: 11-14-2007, 11:28 PM
  5. Diff btw typedef struct and struct?
    By willkoh in forum C Programming
    Replies: 3
    Last Post: 09-24-2005, 02:27 PM

Tags for this Thread