D string to C struct fixed-size array
bdh
ben.h at posteo.net
Tue Jan 5 03:47:11 UTC 2021
On Monday, 4 January 2021 at 18:05:40 UTC, tsbockman wrote:
>> /* XXX: haven't done private members yet, wonder if they're
>> needed to
>> * complete this */
>
> Leaving out the private members of a struct changes its size,
> and sometimes its alignment. This will definitely break things
> if you ever allocate an instance yourself (including via the
> stack).
>
> If you only EVER access that type via pointers to instances
> allocated by an API which internally uses the complete, correct
> definition, and ALL of the private members are at the end of
> the struct, it should work - but those are two big "if"s, and
> too easy to unthinkingly violate later by accident. So, it is
> best to ensure that the struct definition matches precisely on
> both the D and C sides of the API, or at least enough to ensure
> that the size and alignment are the same.
While the struct that comment is from (ImageInfo) had been fixed
before your message[0], I do appreciate the information here
since I wasn't aware of it before and it helped solve the issue
(see my reply to Steve). Thanks.
[0]: https://repo.or.cz/magickd.git/commit/27ac82b110
More information about the Digitalmars-d-learn
mailing list