Pre-RFC: extern types with known alignment

regular extern types have fully unknown size and alignment. currently this is done by making size_of_val and align_of_val.

however, in many cases it may be desirable to have a thin DST with known alignment and unknown size. importantly, this will allow getting the offset of a trailing opaque field, even the struct has other fields.

the syntax would be very simple, for example:

extern {
  #[align(1)]
  type TrailingBytes;
}

in this case the align attribute specifies an exact alignment, since there are no other factors visible to the compiler that could affect alignment.

1 Like

Related: Pre-RFC: #[align] attribute

actually, thinking about existing semantics, i think #[repr(packed)] is actually the right fit, since it is used to lower the required alignment of a type.

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