HN2new | past | comments | ask | show | jobs | submitlogin

It worked for Microsoft VC++ for a long time.


Nowadays they rely on COM for that purpose, which is nice as idea, if the tooling wasn't so clunky.


MSVC++ 2015 or later has a stable ABI independent of COM.


I’m interested in how this works (this thread is now getting old so I’m not sure there will be replies…)

One of the important aspects of a stable ABI is the ability for clients to continue to work even after the size of a remote type changes… for instance, if Foo is a type defined in Foo.dll, and I link to it, and my code does `Foo *f = new Foo()`, the compiler will emit code that malloc’s `sizeof(Foo)` bytes on the heap. If later on, Foo gets a new member variable “m”, it will increase in size, and now code in Foo.dll will segfault if it tries to access `this->m`, if a client allocated it.

COM solves this by basically not letting you do `new Foo`, but instead you have to ask COM itself to allocate and return an instance for you, with something like `CoCreateInstance`. This allows .dll’s to evolve even if the size of the object changes, by abstracting away things like size information so that clients don’t care about it. ObjC solves this similarly with `[SomeClass alloc]`, where clients just ask the class to alloc itself and returns a pointer (which is delayed until runtime, not in the emitted code), and Swift solves it with value witness tables which delay the lookup of size/stride information until runtime.

I don’t understand how, you can write .dll’s with not only a stable ABI, but the ability to actually evolve your types, in plain vanilla C++… I think the language itself has painted itself into a corner that prevents things like this.


Yes, hence one of the reasons why WinRT came to be, as COM evolution.

You get .NET metadata, IInspectable, and an improved type system, basically .NET CLS.

It doesn't expose everything C++ can do, but enough C with classes, OOP ABI and generics.

https://learn.microsoft.com/en-us/uwp/winrt-cref/winmd-files

Basically what COM vNext was going to be, if it wasn't for .NET pivot (see Ext-VOS).

However the tooling is as clunky as using ATL.


Which is creating a bunch of headaches for full ISO C++20 semantics, and most likely needs to be fixed by when ISO C++23 gets fully supported.

One example where this shows up is [[no_unique_address]].




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: