goat icon indicating copy to clipboard operation
goat copied to clipboard

Structs, C ABI + always the most optimized field arrangement?

Open PaperPrototype opened this issue 2 years ago • 8 comments

Is it possible to satisfy optimized field arrangement without re-ordering fields at compile time?

Yes.

Just force the developer to align fields in an optimized order, and throw a compiler error if they don't.

Why do this? I'm not sure exactly what the C ABI is, but I do know it has to do with field re-ordering in structs. It would be nice if Golang could comply with the C ABI, making it much easier to use Golang alongside C.

Go fmt could automatically re-order fields for the developer on save to prevent the mental overhead of field re-ordering.

PaperPrototype avatar Nov 06 '22 22:11 PaperPrototype