c++pimpl-idiombinary-compatibility

Why binary compatibility?


I am learning PIMPL idiom. One of its advantage is binary compatibility. I am wondering what the advantages of binary compatibility are. Thanks!


Solution

  • It avoids the Fragile Binary Interface Problem. It goes like this:

    1. Program uses library.

    2. User upgrades library. Upgrade changes something in the library's binary interface.

    3. Program now doesn't work until it is recompiled because it was built to the old binary interface.

    One of the advantages of the PIMPL idiom is that it allows you to move things that would normally be part of the public interface of a class into its private interface (in fact, into the interface of a private class). You can change the private interface without breaking binary compatibility.