C structs, unions and enums: modelling data with custom types

10 steps · about 3 h 50 min · Intermediate

  1. C Programming Course Notes - Structures, Unions, and Enumerated Types (guide, University of Illinois Chicago (J. Bell), 30 min)

    It covers structs, unions and enums in one place, so you see how the three fit together before the details.

  2. Structs, Enums and Unions in C (blog, Coder Corner, 15 min)

    A short, gentle walkthrough with typedef examples, including an enum nested inside a struct.

  3. Enum, Typedef, Structures and Unions CS 2022: Introduction to C (doc, Cornell University, 20 min)

    These lecture slides show how enum values are numbered, that enums are basically integers, and how structs are allocated.

  4. C Unions (tutorial, W3Schools, 15 min)

    Hands-on examples let you see members sharing memory and check the size of a union with sizeof.

  5. Structs, Unions, and Enums CS449 Spring 2016 (doc, University of Pittsburgh, 20 min)

    It adds the rules for unions (only the last-written member is valid to read) and the first warning about padding.

  6. C Struct Alignment and Padding (tutorial, W3Schools, 15 min)

    It explains why sizeof a struct is often larger than the sum of its members, and how reordering fields helps.

  7. C Structs, Unions & Data Alignment: Memory Layout Mastery (article, TopicTrick, 20 min)

    It compares badly and well ordered structs, introduces offsetof and packed structs, and shows tagged unions.

  8. Unions, Enums, Bit Fields, and Typedefs (tutorial, Awesome Modern C++ tutorial, 35 min)

    It combines all the pieces into tagged unions and protocol frame parsing, and adds bit-fields and typedef.

  9. C Unions for Shared Memory Layouts (article, Alexander Obregon, 20 min)

    It deepens your model of overlapping storage, alignment and safe byte-level views with memcpy.

  10. Deep Dive into Unions in C and C++ (reference, GitHub Gist (MangaD), 40 min)

    It is the advanced capstone, covering union lifetime, aliasing, padding bytes and real-world patterns.