D string to C struct fixed-size array
tsbockman
thomas.bockman at gmail.com
Mon Jan 4 18:05:40 UTC 2021
On Monday, 4 January 2021 at 02:17:33 UTC, bdh wrote:
> I'm pretty sure it's correct?
>
> Here's the D version:
>
> https://repo.or.cz/magickd.git/blob/e5d06e939:/source/magickd/core/c/image.d#l751
>
> Here's the C version:
>
> http://hg.code.sf.net/p/graphicsmagick/code/file/a622095da492/magick/image.h#l683
> /* 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.
More information about the Digitalmars-d-learn
mailing list