TRT
Sign in

Core · Module 4 · Lesson 8 of 9

Opaque Pointers and API Encapsulation

Enforce information hiding using incomplete struct declarations, guarantee ABI stability across library updates, and design opaque handle APIs.

Pro — members onlyAbout 15 minutes

By the end you can

  • Expose incomplete struct types in public header interfaces to enforce encapsulation
  • Confine complete struct definitions to implementation translation units
  • Preserve Application Binary Interface (ABI) compatibility across library updates
  • Implement constructor and destructor lifecycle pairs for opaque handles

Builds on Dynamic Arrays and Linked Node Structures.

01 · A question first

Why does adding a single private field to a struct in a shared library header break already-compiled client binaries without warning? And how does C achieve bulletproof object encapsulation without classes or access specifiers?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Why it is correct
  • What it costs
  • Pitfalls and variations
  • Where it is used

03 · Practice

Something wrong with this lesson? Report a problem