Zig / C++ Interop
Postedabout 2 months agoActiveabout 2 months ago
tuple.appTechstory
calmmixed
Debate
40/100
C++ZigInteropAbiSystems Programming
Key topics
C++
Zig
Interop
Abi
Systems Programming
The article discusses achieving interoperability between Zig and C++ by leveraging the C ABI, sparking a discussion on the complexities and challenges of interop, including size/alignment communication and ABI nuances.
Snapshot generated from the HN discussion
Discussion Activity
Light discussionFirst comment
5h
Peak period
4
3-6h
Avg / period
3
Comment distribution15 data points
Loading chart...
Based on 15 loaded comments
Key moments
- 01Story posted
Nov 11, 2025 at 3:09 AM EST
about 2 months ago
Step 01 - 02First comment
Nov 11, 2025 at 8:01 AM EST
5h after posting
Step 02 - 03Peak activity
4 comments in 3-6h
Hottest window of the conversation
Step 03 - 04Latest activity
Nov 12, 2025 at 4:53 PM EST
about 2 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45885135Type: storyLast synced: 11/20/2025, 7:45:36 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
It was an unholy welding of the two languages that mostly let Objective-C apps adopt some libraries from the broader C++ ecosystem. Plus the occasional cross-platform C++ codebase used it as a thin shim to provide a Cocoa-based UI...
Rename a file to .mm and start using Objective C APIs. Very good interop
Aren't there ABI cases where e.g.
would be passed in e.g. fp registers whereas would not?I sort of mentioned this in the blog but this is good clarification.
> if you want to pass a shared_ptr to Zig, you need to pass a pointer to the shared pointer
For lore, I believe this GitHub thread is where I first learned about the how types of the same size/alignment can still have different ABIs :) https://github.com/microsoft/win32metadata/issues/623#issuec...
Direct C++ interop is doable, by embedding Clang into Zig and using its AST, but this is significantly more work and it needs to be done in the Zig compiler. As a Zig user, going through C is about as good as you can do, probably.
fn stackExample() void {
It's a bit ugly due to cbindgen not supporting const-generic expressions and macro-expansion being nightly-only. It seems like this will be a generally useful mechanism to be able to use values which are not traditionally FFI-safe across FFI boundaries.
[0]: https://github.com/RediSearch/RediSearch/blob/cfd364fa2a47eb...