Sign up

Opaque structures

How should I handle opaque structures? For example, I have two c header, clutter-types.h and clutter-color.h. In clutter-color.h ClutterColor structure is defined. And in clutter-types.h there is typedef ClutterColor ClutterColor.
clutter-types.h
...
typedef _ClutterColor ClutterColor;
...

clutter-color.h
...
struct _ClutterColor
{
...
}
...

I converted .h to .d and now I have:
cluttertypes.d<br>...<br>alias ClutterColor ClutterColor;
...
struct _ClutterColor; // <-- dstep added it
...

cluttercolor.d<br>...<br>struct ClutterColor
{
...
}
...

I can manually make right aliases, but I'm not sure this is the best way. May be there is more correct way to handle opaque structures? I'm sure Gtk+ bindings solve this problem somehow...

Re: Opaque structures

On 11/30/2013 09:45 PM, Alexandr Druzninin wrote:

How should I handle opaque structures? For example, I have two c header, clutter-types.h and clutter-color.h. In clutter-color.h ClutterColor structure is defined. And in clutter-types.h there is typedef ClutterColor ClutterColor.
clutter-types.h
...
typedef _ClutterColor ClutterColor;
...

clutter-color.h
...
struct _ClutterColor
{
...
}
...

I converted .h to .d and now I have:
cluttertypes.d<br>...<br>alias ClutterColor ClutterColor;
...
struct _ClutterColor; // <-- dstep added it
...

cluttercolor.d<br>...<br>struct ClutterColor
{
...
}
...

I can manually make right aliases, but I'm not sure this is the best way. May be there is more correct way to handle opaque structures? I'm sure Gtk+ bindings solve this problem somehow...

The script/app that generates the bindings for GtkD parses the
documentation. Witch only documents the typedef and it turns it into:

struct ClutterColor{}

A real opaque struct might be better:

struct ClutterColor;

Re: Opaque structures

On Sat, 30 Nov 2013 23:21:48 +0100, Mike Wey wrote:

The script/app that generates the bindings for GtkD parses the
documentation. Witch only documents the typedef and it turns it into:

struct ClutterColor{}

A real opaque struct might be better:

struct ClutterColor;

I mean that D variant don't compile, because real definition of ClutterColor is placed in one module, and alias ClutterColor ClutterColor (with definition of _ClutterColor as an opaque structure) is placed in other module.
And if I use ClutterColor in application compiler finds only definition of ClutterColor only as an opaque structure and don't compile because don't know its size.

Re: Opaque structures

On 12/01/2013 08:21 AM, Alexandr Druzninin wrote:

On Sat, 30 Nov 2013 23:21:48 +0100, Mike Wey wrote:

The script/app that generates the bindings for GtkD parses the
documentation. Witch only documents the typedef and it turns it into:

struct ClutterColor{}

A real opaque struct might be better:

struct ClutterColor;

I mean that D variant don't compile, because real definition of ClutterColor is placed in one module, and alias ClutterColor ClutterColor (with definition of _ClutterColor as an opaque structure) is placed in other module.
And if I use ClutterColor in application compiler finds only definition of ClutterColor only as an opaque structure and don't compile because don't know its size.

If the struct is opaque you should only be using pointers to it.