"zero-length" arrays and rust ffi

There was a thread a few years ago about this:

I was wondering what the current recommended practice was for dealing with these?

I see that DSTs are now a thing, but the nomicon says DST pointers (wide pointers) and tuples are not a concept in C, and as such are never FFI-safe.

Any advice appreciated.

So far, the best example I've seen is from bindgen:


But I was hoping for something simpler and that didn't require using bindgen. I only have one or two of these. I could of course do everything bindgen's doing, but I'd like to fully understand the tradeoffs involved.

If I am correct, maybe only write a [WORD; 1] for structs and only use its reference or raw pointer other than creating an instance of itself? OS-oriented adaptions like winapi somehow do this in practice.

Yes, it seems there's no better accepted option right now. I see various projects have written tooling around this but given how common this is and relevant to FFI, it would be nice if rust had a native wrapper for it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.