PART 1 / LESSON 5 · Overview free · interactive lesson in the full course

Unions, enums and data representation

Explore alternative interpretations of stored bytes, tagged unions and the representation limits that matter in portable C.

View lesson accessAll lessons

What the lesson covers

The course lesson is called Same bytes, different meaning. The gateway team reports messages decoding as the wrong type, a float that prints as a ten-digit integer, and a state name table that is indexed past its end.

Before you start

Question to think about: What information tells the consumer which union member is meaningful?

Preparation exercise: Define the invariants of a tagged message and identify what a validator must reject.

This is an original public study prompt, not the paid lesson or its solution. The interactive course contains the walkthroughs, labs, exercises and recaps.

Read the free embedded C articles for additional practice.

Test your understanding

Practice free firmware interview questions and mock interviews · Assess your readiness