digitalmars.D - X header help
- Lucas Goss (26/26) Mar 11 2006 Has anyone translated X C headers to D? I have X.h done and Xlib.h is
- Unknown W. Brackets (15/49) Mar 11 2006 Actually, you want it to be a typedef or alias. You could just use its:
- Lucas Goss (2/4) Mar 11 2006 Ah, right. Thanks, that helped.
- Kyle Furlong (2/7) Mar 11 2006 Actually the C typedef I believe is more like the D alias.
- Unknown W. Brackets (2/10) Mar 11 2006
- John Reimer (5/18) Mar 11 2006 It's safer/easier to use "alias" when converting from C typedef.
- Lucas Goss (3/6) Mar 12 2006 Yeah, I use "alias" when converting any C typedef just to be safe.
- John Reimer (5/39) Mar 11 2006 These headers could be quite useful! Please submit them to the D
- Lucas Goss (4/8) Mar 12 2006 Yes, I think the headers are useful too and I plan on submitting them to...
- Dejan Lekic (7/7) Mar 14 2006 One guy (essiene) and I are working on it. Snapshot is available at:
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.
Mar 11 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.
Mar 11 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.
Mar 11 2006
Lucas Goss wrote:Unknown W. Brackets wrote:Actually the C typedef I believe is more like the D alias.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.
Mar 11 2006
IMHO, in the case of function pointers typedefs usually make sense. -[Unknown]Lucas Goss wrote:Unknown W. Brackets wrote:Actually the C typedef I believe is more like the D alias.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.
Mar 11 2006
Unknown W. Brackets wrote:IMHO, in the case of function pointers typedefs usually make sense. -[Unknown]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. -JJRLucas Goss wrote:Unknown W. Brackets wrote:Actually the C typedef I believe is more like the D alias.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.
Mar 11 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
Mar 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
Mar 11 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
Mar 12 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
Mar 14 2006









Lucas Goss <lgoss007 gmail.com> 