D string to C struct fixed-size array

Steven Schveighoffer schveiguy at gmail.com
Mon Jan 4 17:24:27 UTC 2021


On 1/3/21 9:17 PM, bdh wrote:
> On Sunday, 3 January 2021 at 11:16:25 UTC, rikki cattermole wrote:
>> Your definition of Image is probably wrong.
>>
>> You may have missed a pointer (8 bytes).
> 
> 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 
> 
> 

How to test:

in D-land:

import magickd.core.c.image : Image;

pragma(msg, Image.filename.offsetof);

In C-land

#include <stdio.h>
#include <magick/image.h>

int main()
{
    Image *ptr = NULL;
    printf("%ld", &(ptr->filename)); // may need a different specifier
}

If those are not the same, then your struct is off.

-Steve


More information about the Digitalmars-d-learn mailing list