Thread overview
X header help
Mar 12, 2006
Lucas Goss
Mar 12, 2006
Lucas Goss
Mar 12, 2006
Kyle Furlong
Mar 12, 2006
John Reimer
Mar 12, 2006
Lucas Goss
Mar 12, 2006
John Reimer
Mar 12, 2006
Lucas Goss
Mar 15, 2006
Dejan Lekic
March 12, 2006
Has anyone translated X C headers to D? I have X.h done and Xlib.h is partly done.

Anyways, I've run into some code that I'm not sure how to translate it to D.

//----------
typedef void (*XIMProc)(
    XIM,
    XPointer,
    XPointer
);

// then later a struct which uses the above function pointer

typedef struct {
    XPointer client_data;
    XIMProc callback;
} XIMCallback;
//----------

I translated the it as:
//----------
void function(XIM, XPointer, XPointer) XIMProc;

struct XIMCallback
{
	XPointer client_data;
	// XIMProc callback; ??? nope.
	// void* callback = XIMProc(); ??? nope.
}
//----------

Obviously it failed to compile, but I'm not sure how to translate it.
March 12, 2006
Actually, you want it to be a typedef or alias.  You could just use its:

typedef void (*XIMProc)(XIM, XPointer, XPointer);

Which should be equivalent to:

typedef void function(XIM, XPointer, XPointer) XIMProc;

The important thing here is the typedef; the way you tried doesn't specify this is a type, but is more like defining a variable.

Then you would use:

struct XIMCallback
{
	XPointer client_data;
	XIMProc callback;
}

Hope that helps.

Thanks,
-[Unknown]


> Has anyone translated X C headers to D? I have X.h done and Xlib.h is partly done.
> 
> Anyways, I've run into some code that I'm not sure how to translate it to D.
> 
> //----------
> typedef void (*XIMProc)(
>     XIM,
>     XPointer,
>     XPointer
> );
> 
> // then later a struct which uses the above function pointer
> 
> typedef struct {
>     XPointer client_data;
>     XIMProc callback;
> } XIMCallback;
> //----------
> 
> I translated the it as:
> //----------
> void function(XIM, XPointer, XPointer) XIMProc;
> 
> struct XIMCallback
> {
>     XPointer client_data;
>     // XIMProc callback; ??? nope.
>     // void* callback = XIMProc(); ??? nope.
> }
> //----------
> 
> Obviously it failed to compile, but I'm not sure how to translate it.
March 12, 2006
Unknown W. Brackets wrote:
> The important thing here is the typedef; the way you tried doesn't specify this is a type, but is more like defining a variable.

Ah, right. Thanks, that helped.
March 12, 2006
Lucas Goss wrote:
> Unknown W. Brackets wrote:
>> The important thing here is the typedef; the way you tried doesn't specify this is a type, but is more like defining a variable.
> 
> Ah, right. Thanks, that helped.

Actually the C typedef I believe is more like the D alias.
March 12, 2006
IMHO, in the case of function pointers typedefs usually make sense.

-[Unknown]


> Lucas Goss wrote:
>> Unknown W. Brackets wrote:
>>> The important thing here is the typedef; the way you tried doesn't specify this is a type, but is more like defining a variable.
>>
>> Ah, right. Thanks, that helped.
> 
> Actually the C typedef I believe is more like the D alias.
March 12, 2006
Unknown W. Brackets wrote:
> IMHO, in the case of function pointers typedefs usually make sense.
> 
> -[Unknown]
> 
> 
>> Lucas Goss wrote:
>>> Unknown W. Brackets wrote:
>>>> The important thing here is the typedef; the way you tried doesn't specify this is a type, but is more like defining a variable.
>>>
>>> Ah, right. Thanks, that helped.
>>
>> Actually the C typedef I believe is more like the D alias.


It's safer/easier to use "alias" when converting from C typedef. typedef are so type safe that they cause tons of problems when creating a D interface to C code.  For strict D use, of course, typedef's are great.

-JJR
March 12, 2006
Lucas Goss wrote:
> Has anyone translated X C headers to D? I have X.h done and Xlib.h is partly done.
> 
> Anyways, I've run into some code that I'm not sure how to translate it to D.
> 
> //----------
> typedef void (*XIMProc)(
>     XIM,
>     XPointer,
>     XPointer
> );
> 
> // then later a struct which uses the above function pointer
> 
> typedef struct {
>     XPointer client_data;
>     XIMProc callback;
> } XIMCallback;
> //----------
> 
> I translated the it as:
> //----------
> void function(XIM, XPointer, XPointer) XIMProc;
> 
> struct XIMCallback
> {
>     XPointer client_data;
>     // XIMProc callback; ??? nope.
>     // void* callback = XIMProc(); ??? nope.
> }
> //----------
> 
> Obviously it failed to compile, but I'm not sure how to translate it.


These headers could be quite useful!  Please submit them to the D bindings project at dsource.org when you are done?  I could use them in a project or two in the future. :)

-JJR
March 12, 2006
John Reimer wrote:
> These headers could be quite useful!  Please submit them to the D bindings project at dsource.org when you are done?  I could use them in a project or two in the future. :)
> 

Yes, I think the headers are useful too and I plan on submitting them to the D bindings when done.

Lucas
March 12, 2006
John Reimer wrote:
> It's safer/easier to use "alias" when converting from C typedef. typedef are so type safe that they cause tons of problems when creating a D interface to C code.  For strict D use, of course, typedef's are great.

Yeah, I use "alias" when converting any C typedef just to be safe.

Lucas
March 15, 2006
One guy (essiene) and I are working on it. Snapshot is available at: http://gnu.nu6.org:8000/files/dxlib.tar.bz2 .

It would be nice if you join our D IRC channel: irc://irc.freenode.org/D and discuss the code further with us (my nick there is Dejan) .

Kind regards

Dejan Lekic
  http://dejan.lekic.org