5 ms·
C++ ABIs are why Win32 settled on things like COM to do cross-module passing of objects. Because nobody could agree on a standard, the COM standard enforced a
by Dwedit 2mo ago
C++ ABIs are why Win32 settled on things like COM to do cross-module passing of objects. Because nobody could agree on a standard, the COM standard enforced a very specific calling convention, and a very specific vtable layout for COM objects.
- pjmlp 2mo agoNot only, there is also XPC and IO/DriverKit on Apple, Android IPC, D-BUS, FIDL on Fucshia,.... Also C ABI also does not exist, people keep mistaking the ABI of their favourite C compiler with the OS ABI, which only overlap if the OS was written in C to start with. For example on mainframes and micros, naturally not written in C, it is either a bytecode based ABI like TIMI on IBM i, or language environments like on z/OS, ClearPath MCP, OS 2200 and so forth. And as a reminder, from a famous WG14 and WG21 member, and former Rust contributor, "To Save C, We Must Save ABI" https://thephd.dev/to-save-c-we-must-save-abi-fixing-c-function-abi https://thephd.dev/to-save-c-we-must-save-abi-fixing-c-funct...
- bheadmaster 2mo agoSystem V ABI is pretty standardized.
- pjmlp 2mo agoUNIX, the reason why C exists.
- bheadmaster 2mo agoYeah, I'm not interested in decoding what you meant by your aphorism. Either say what you mean or don't.
- pjmlp 2mo agoGreat, so lets save us both time.
- mort96 2mo agoUh, GNU does define an OS ABI...
- mohamedkoubaa 2mo agoGiven OOP, the only ABI for an object is a vtable and that is left unspecified (for good reason) by the C++ standard. COM said, "objects are cool and modules are cool so we need an ABI for objects" and specified a vtable. It isn't the only programming model which continued from the same observation: Python did too with its absolutely abysmal leaky PyObject ABI
- pjmlp 2mo agoSOM predates COM, and is even cooler, as it supported class inheritance, metaclasses and Smalltalk as target language. On OS/2, Smalltalk enjoyed a role similar to what would be .NET and VB on Windows. Sure you can use delegation with aggregation, and type libraries (nowadays .NET metadata), but still isn't as ergonomic.
- rramadass 2mo agoCOM designers were inspired by C++ but their goals were different. They were designing a language-neutral binary standard (aka ABI) and hence took C++'s approach and tweaked it for their specification. Here is an earlier comment of mine with some details - https://news.ycombinator.com/item?id=49142987 https://news.ycombinator.com/item?id=49142987
- quotemstr 2mo agoAnd COM enforces lifecycle rules, transparent remoting, uniform activation (constructors basically), security primitives, marshalling, transparent async calls (yes, you can call any method asynchronously), and a ton of other things. It's actually very good and it's a shame most don't know about it and most of the rest sneer at it.
- dblohm7 2mo agoI agree! (Though you cannot call just any method asynchronously; the interface's IDL needs specific annotations and the underlying object needs to implement ICallFactory.)
- quotemstr 2mo agoJust add async_uuid to your IDL locally and rerun MIDL. The server doesn't know or care that it's being called asynchronously. It's a pure client thing. If you're calling an IFoo in a different apartment, you can do the call asynchronously by changing your client configuration without the IFoo implementation having to be aware that anything is going on. You can also use IRpcChannelBuffer3 to make the call asynchronously no matter what the IDL says. You'll have to write the proxy plumbing yourself, but it'll work, and you don't even need to rerun MIDL.
- rramadass 2mo agoWell said. COM was one of the best realizations of "Component-based Software Engineering" and Brad Cox's "Software-IC" model. It was a binary standard and so components could be written in any language and yet be assured of perfect interoperability provided you followed all the rules/conventions. There was a bunch of boiler-plate for the framework itself but once you understood it, everything was smooth sailing in your language of choice. One of the things i always advise people is not to focus only on the current way of doing things but to study older well-known libraries/frameworks/architectures/kernels/etc. to really understand "Software Engineering" from many perspectives. That is where insight comes from and real understanding happens. For people interested in understanding COM, see the classic Essential COM by Don Box.
- WalterBright 2mo ago> and a very specific vtable layout for COM objects Fun fact: Microsoft developed COM based on how Zortech C++ virtual functions worked. (It predated Microsoft C++ by years.)
- throwlifeaway 2mo agoYou mean... using a vtable? Are you claiming to have invented the concept of vtables?
- WalterBright 2mo agoYes, the vtable. Microsoft at the time equipped their COM team with Zortech C++ and so they used the Zortech vtable. No, I did not invent the concept of vtables.
- rramadass 2mo agoAFAIK, the first design for implementation of vtables was by Bjarne Stroustrup in his paper Multiple Inheritance for C++ in 1986/1987. Pdf at https://www.google.com/goto?url=CAESawHuR6pN4SDa5tLkqrSuoaotMopYVPZEG3pYF5D68utkJPw-THAe2wj4hWV0R05ljH0BNxsE7SdPMdu4rtdeK9wUpp28uiK7xurAm5Bak0ljQeGCM42wbmbl_Vxzkx0vOwvH4Acmt6szcP38 https://www.google.com/goto?url=CAESawHuR6pN4SDa5tLkqrSuoaot... and reissue at https://www.researchgate.net/publication/2396782_Multiple_Inheritance_for_C https://www.researchgate.net/publication/2396782_Multiple_In... I read this in one of the documentation books (still have it somewhere) which came with SCO Unix (don't recall the date). This book contained articles on C++ only and was an introduction to the language and compiler (since the language was very new). I also remember that it had an article on Template mechanism. Next was Jan Gray from Microsoft's excellent 1994 article in MSDN titled C++: Under the Hood which explained class layouts/vtables/etc. It is still a excellent read today. Pdf at https://www.google.com/goto?url=CAESewHuR6pNy2XLp9fzgwckhWpgEhmu2Pq4tHNfAtOsi0s2DQvpgj-jfq-ZZRAliR8CONvoFJ385Kx_GsSDmhu1yaAd9yhEQdFXChmGvH4MvNwvnitrbjG55Xa_Ay-miXrigsz-0KwgtBqdYPVTQZGZmEzQhrya-rD8z8Md1w== https://www.google.com/goto?url=CAESewHuR6pNy2XLp9fzgwckhWpg... Finally of course you have Inside the C++ Object Model by Stanley Lippman explaining everything in detail.
- vintagedave 2mo agoAnd Delphi came along and used the same layout, so an interfaced Delphi object has beautiful COM interop.
- pjmlp 2mo agoWhich is also used by C++ Builder. In a tragic way, given the prevalence of COM in Windows, especially since Vista, someone at Microsoft should offer a few Delphi and C++ Builder licenses to the teams responsible for doing COM tooling. Because MFC/OLE, ATL, WTL, WRL, C++/WinRT all have their sharp edges and could be so much better, if someone actually cared about productivity and framework ergonomics.