Chapter 9

Structures

Abstract:

This chapter deals with C structures and unions. Some other languages call these records. Structure definitions are covered along with the use of tags and typedefs. The advanced topics of nested structures and bit fields are fully explained with examples. The differences between unions and structures are taught in this chapter.

The layout of structures and unions in memory is shown, as well as the use of the packed attribute. This chapter has many examples to show how structures can be best used in embedded programs for microcontrollers.

Examples and exercises are for the popular PIC™ microcontroller manufactured by Microchip.

Keywords:

Structure

Struct

Union

Member

Field

Bit field

Tag

Attribute

Packed

Get Embedded C Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.