Does #[repr(packed)] have a drop flag?

I am trying to figure out whether data that has repr(packed) has a drop flag or not. None of the documentation seems to mention it. It would seem rather odd for it to contain a drop flag (since that would make FFI difficult).

I feel that it should be mentioned somewhere in the docs whether it has one or not. If it does have one, I would like to be able to remove it (and remove all drop semantics)

Note: my use case is a memory manager for micro-controllers, so the gory details are where I'm at!

The last Nighties don't add drop flags inside structs.

1 Like

For FFI you probably want #[repr(C)] or #[repr(C, packed)], and then you'll get a warning like:

warning: implementing Drop adds hidden state to types, possibly conflicting with `#[repr(C)]`, #[warn(drop_with_repr_extern)] on by default

... at least until you're on a newer rustc that doesn't have drop flags, as @leonardo mentioned.

I keep up to date with the most recent nightly.

If I care about the ordering of my data (and I want it packed) should I use #[repr(packed)] or #[repr(C, packed)]? I thought they were equivalent.

On structs:

  • repr - specifies the representation to use for this struct. Takes a list of options. The currently accepted ones are C and packed, which may be combined. C will use a C ABI compatible struct layout, and packed will remove any padding between fields (note that this is very fragile and may break platforms which require aligned access).
1 Like

awesome, thanks so much guys.

Btw, if you are curious in the library it is:

I hope to be feature-complete and in Alpha soon