logoalt Hacker News

tialaramextoday at 9:55 AM2 repliesview on HN

The interop story is largely a self-fulfilling prophecy. When you start to explore the edges of C ABI compatibility you discover that er... there's actually no ABI compatibility unless somebody did the work and they never did the work.

Two C implementations on the same CPU with 64-bit integers both, unsurprisingly, think 64-bit integers work the same way - because that was obvious. Now, how about 128-bit integers. Ah, turns out implementation A thought they go (lo,hi) but B thought they're obviously (hi,lo) so these types have different ABI between C implementations...

It's not obvious because most software which cares about Windows also needs the Windows API and so couldn't be non-Windows software, but Windows people have a different rule for how 64-bit works than everybody else, LLP64 versus the usual LP64. And there were other options such as ILP64 they're just all basically dead.


Replies

agentultratoday at 11:17 AM

128-bit integers aren’t part of the standard (yet)… but the point is right; platform and architecture matter. Many aspects of them are defined by the compiler implementation.

Also ABI compatibility isn’t part of the C specification. Most implementers use System V ABI compatibility guidelines. Many compilers can output code for different ABI’s calling conventions. There’s more than one! Which you use depends on how crufty the code is and on the platform you are using.

I think the big advantage of C like languages here is the plethora of implementation defined platforms. That’s a huge network effect. If you want to target the 6502? There’s a compiler for it. Some chip you’ve never heard of? Probably some fork of GCC that targets it. Want to call some library function in some foreign binary written in a completely unknown language? If you can finagle the bytes and reverse engineer the calling conventions you can do it with C.

I think it might be that C does leave so much out of the specification and up to the implementation and platform that makes it unique and useful at times.

P-Nutstoday at 11:11 AM

Somebody did do the work! The System V AMD64 ABI definitely defines the registers for __int128, e.g. as first argument to a function it will always be rdi (lo) rsi (hi) and for return value it will always be rax (lo) rdx (hi).