Extern file containers

Hello,

I know it’s possible to pass Zig structs to C/C++ functions using extern, however I don’t know how to do the same with file containers. For example, let’s say I have ‘a.zig’:

pub const A = @This();

field1: bool,
field2: int,
//...

And then I have some C function:

void use_A(A value) {
     //...
}

What’s the syntax for declaring A as extern so that it matches the C ABI?

TLDR: dont use a file struct.

export makes a declaration available for linking.
However that wont work as there is no way to mark a file struct as extern meaning it wont follow the C ABI so it cant be exported.

3 Likes

There is currently no way to declare a file struct as extern. You will have to use a regular declaration: const MyStruct = extern struct {foo: u8};

Related: Gotchas when using a file as a struct?

Welcome to ziggit!

4 Likes