IT lexicon › Programming › Empty base optimization (EBO)

Empty base optimization (EBO)

Programming På svenska → Updated: 2026-11-06

The C++ exception that lets an empty base class take zero bytes, even though every object must otherwise be at least one byte in size.

In C++ every complete object has its own address, so even a class with no members has a sizeof of 1. As a member it drags in a byte plus padding. As a base class, though, it may share an address with the derived object and occupy nothing. The standard library leans on this heavily: std::unique_ptr with the default deleter is exactly the size of a raw pointer, and containers carry stateless allocators for free.

C++20 extended the trick to members with [[no_unique_address]]. Microsoft's compiler ignores that attribute, because the changed layout would break its ABI, and offers [[msvc::no_unique_address]] instead. It has also long skipped EBO under multiple inheritance unless you write __declspec(empty_bases). Layout is ABI, and ABI doesn't get fixed after the fact.

← Back to the lexicon