Thread overview
Re: Converting C .h Files to D Modules
Mar 21, 2012
Pedro Lacerda
Mar 21, 2012
Andrej Mitrovic
Mar 21, 2012
bearophile
Mar 21, 2012
Andrej Mitrovic
Mar 21, 2012
dnewbie
Mar 21, 2012
Pedro Lacerda
March 21, 2012
Ouch, void* is the same in both languages, sorry. I addressed a new problem:

typedef struct SomeFunctions {
    void *(*funcA)(char*, size_t);
    void *(*funcB)(void);
} SomeFunctions;

How do I convert that functions references into an D struct?


On Tue, Mar 20, 2012 at 3:01 PM, Pedro Lacerda <kanvuanza@gmail.com> wrote:

> Hi all,
>
> How to convert the following struct to D?
>
> typedef struct S {
>     int type;
>     void *obj;
> } S;
>
> I didn't found anything at http://dlang.org/htomodule.html.
>


March 21, 2012
On 3/21/12, Pedro Lacerda <kanvuanza@gmail.com> wrote:
> Ouch, void* is the same in both languages, sorry. I addressed a new problem:
>
> typedef struct SomeFunctions {
>     void *(*funcA)(char*, size_t);
>     void *(*funcB)(void);
> } SomeFunctions;
>
> How do I convert that functions references into an D struct?

extern(C)
struct SomeFunctions {
    void function(char*, size_t) funcA;
    void function() funcB;
}

Use HTOD (http://dlang.org/htod.html) if you can to convert .h to .D
(it's Windows-only but might be usable via Wine).
March 21, 2012
Andrej Mitrovic:

> extern(C)
> struct SomeFunctions {
>     void function(char*, size_t) funcA;
>     void function() funcB;
> }


Are you sure that works?
If that doesn't work then use this and write a bug report:

struct SomeFunctions {
    extern(C) void function(char*, size_t) funcA;
    extern(C) void function() funcB;
}

Bye,
bearophile
March 21, 2012
On 3/21/12, bearophile <bearophileHUGS@lycos.com> wrote:
> Are you sure that works?

It's easy to test:

extern(C)
struct SomeFunctions {
   void function(char*, size_t) funcA;
   void function() funcB;
}

void main()
{
    writeln(typeof(SomeFunctions.funcA).stringof);
}
March 21, 2012
On Wednesday, 21 March 2012 at 01:09:58 UTC, Andrej Mitrovic wrote:
> On 3/21/12, Pedro Lacerda <kanvuanza@gmail.com> wrote:
>> Ouch, void* is the same in both languages, sorry. I addressed a new problem:
>>
>> typedef struct SomeFunctions {
>>     void *(*funcA)(char*, size_t);
>>     void *(*funcB)(void);
>> } SomeFunctions;
>>
>> How do I convert that functions references into an D struct?
>
> extern(C)
> struct SomeFunctions {
>     void function(char*, size_t) funcA;
>     void function() funcB;
> }
>
> Use HTOD (http://dlang.org/htod.html) if you can to convert .h to .D
> (it's Windows-only but might be usable via Wine).

Why not
     void* function(char*, size_t) funcA;
     void* function() funcB;

March 21, 2012
On Tue, Mar 20, 2012 at 10:53 PM, dnewbie <run3@myopera.com> wrote:

> On Wednesday, 21 March 2012 at 01:09:58 UTC, Andrej Mitrovic wrote:
>
>> On 3/21/12, Pedro Lacerda <kanvuanza@gmail.com> wrote:
>>
>>> Ouch, void* is the same in both languages, sorry. I addressed a new problem:
>>>
>>> typedef struct SomeFunctions {
>>>    void *(*funcA)(char*, size_t);
>>>    void *(*funcB)(void);
>>> } SomeFunctions;
>>>
>>> How do I convert that functions references into an D struct?
>>>
>>
>> extern(C)
>> struct SomeFunctions {
>>    void function(char*, size_t) funcA;
>>    void function() funcB;
>> }
>>
>> Use HTOD (http://dlang.org/htod.html) if you can to convert .h to .D
>> (it's Windows-only but might be usable via Wine).
>>
>
> Why not
>     void* function(char*, size_t) funcA;
>     void* function() funcB;
>
>
Andrej, thanks for the solution.
dnewbie, you're correct, the return type is void* instead of void.
bearophile, the extern(C) where Andrej pointed works well on gdc-4.6.2

Thanks :)