cast a C char array - offset ?
irtcupc via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 2 05:36:46 PST 2015
On Monday, 2 February 2015 at 12:57:37 UTC, Mike Parker wrote:
> On 2/2/2015 9:16 PM, irtcupc wrote:
>> The manual section about interfacing from c states that
>> "type[]" is
>> inter-compatible from C to D,
>>
>> however, I face this strange case:
>>
>> - C declaration:
>> char identifier[64];
>>
>> - D declaration:
>> char[64] identifier;
>>
>> - the result is only correct if i slice by (- pointer size):
>> char[64] fromC(char[64] * thing)
>> {
>> const offs = size_t.sizeof;
>> return thing[-offs.sizeof .. $-offs];
>> }
>>
>> Is this correct ?
>
> That's looking pretty wonky. You're slicing a pointer to a
> fixed-size array. Why have you declared the parameter as a
> pointer? What problem are you trying to solve? It would help a
> bit to see the declaration of the C function that's giving you
> the array.
It looks like it's here:
https://code.google.com/p/beaengine/source/browse/trunk/beaengineSources/Includes/Routines_Disasm.c#763
However i haven't spent the time to dive in there since i'm not a
C guy at all.
More information about the Digitalmars-d-learn
mailing list