Home > front end >  Enabling the empty base class optimization globally in a C project on Windows
Enabling the empty base class optimization globally in a C project on Windows

Time:10-26

MSVC seems to disable empty base class optimization (EBO/EBCO) when using multiple inheritance. Sadly, this means that other compilers targetting windows have to also disable EBO in such scenarios. Now, MSVC provides __declspec(empty_bases) for re-enabling it, but now you have to put this attribute in every class that relies EBO.

Is there a way to disable this behavior globally? That is, are there any compiler flags that will re-enable EBO for a project?

(I'm mainly interested in clang with the GNU command line).

CodePudding user response:

Is there a way to disable this behavior globally?

That would break ABI compatibility with every type declared by any C code on your platform. Including code from your standard library or any pre-compiled library you link to, as well as any DLLs and the like. So... no, there is no way to do that.

Platform ABIs, even when they are wrong, are not optional. If you want to have a type that doesn't follow platform ABI rules, that type's declaration has to have something in it to distinguish itself from those which do follow the platform's ABI rules.

  • Related