atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
231 stars 31 forks source link

Distinguish between size of type and padding for alignment #130

Open Laeeth opened 5 years ago

Laeeth commented 5 years ago

Dpp should represent the padding as a private ubyte[n] padding3__ and the padding should not be part of the type blob itself.

atilaneves commented 5 years ago

What would this accomplish?

Laeeth commented 5 years ago

Why wouldn't you convey the information to the user?

If you have a type T that is a char it might take up 8 bytes with padding. But so might a static array of 8 of the T. So isn't it something important?

You need to know on the other side how big the thing is.

atilaneves commented 5 years ago

Do you mean that dpp should emit structs with explicit padding in case the D and C++ compilers disagree on how much padding there is? That sounds possible in theory but I don't think it happens in practice.

Laeeth commented 5 years ago

If you make types opaque then you should distinguish between actual size of the type and the padding.

Laeeth commented 5 years ago

It's not because of disagreement but because of static arrays

atilaneves commented 5 years ago

Static arrays aren't any more or less special than other fields - what the other side needs to know is how many bytes it takes up, alignment included.