## digitalmars.D.learn - Converting pointer to struct in struct declaration from C to D

• Rick Noether (28/28) Nov 26 2005 Ok, I'm a bloody neophyte in D
• Hasan Aljudy (3/41) Nov 26 2005 I'm guessing it's
• Rick Noether (7/49) Nov 26 2005 Hi Hasan,
• Kris (5/12) Nov 26 2005 Then, it's not entirely clear what you're asking. In C, something prefix...
• Rick Noether (15/30) Nov 26 2005 Hi Chris,
• Kris (3/13) Nov 26 2005 Oh, right. Then void* is the right thing, unless you decide to use class...
Rick Noether <richard.noether alum.com> writes:
```Ok, I'm a bloody neophyte in D

Let's say in a C header, I have

struct A
{
unsigned long a;
unsigned long b;
};

struct B
{
struct A  x;
struct C* y;
};

My question is what does the corresponding declaration
look like in D? I'm guessing at

struct A
{
uint a;
uint b;
};

struct B
{
A     x;
void* y;
};

I'm particularly uncertain about the conversion
of that "struct C* y"?

Rick
```
Nov 26 2005
Hasan Aljudy <hasan.aljudy gmail.com> writes:
```Rick Noether wrote:
Ok, I'm a bloody neophyte in D

Let's say in a C header, I have

struct A
{
unsigned long a;
unsigned long b;
};

struct B
{
struct A  x;
struct C* y;
};

My question is what does the corresponding declaration
look like in D? I'm guessing at

struct A
{
uint a;
uint b;
};

struct B
{
A     x;
void* y;
};

I'm particularly uncertain about the conversion
of that "struct C* y"?

Rick

I'm guessing it's
C* y;
```
Nov 26 2005
Rick Noether <richard.noether alum.com> writes:
```On Sat, 26 Nov 2005 17:29:50 -0700 Hasan Aljudy wrote:

Rick Noether wrote:
Ok, I'm a bloody neophyte in D

Let's say in a C header, I have

struct A
{
unsigned long a;
unsigned long b;
};

struct B
{
struct A  x;
struct C* y;
};

My question is what does the corresponding declaration
look like in D? I'm guessing at

struct A
{
uint a;
uint b;
};

struct B
{
A     x;
void* y;
};

I'm particularly uncertain about the conversion
of that "struct C* y"?

Rick

I'm guessing it's
C* y;

Hi Hasan,

In my example "C" itself is not a declared type,
I guess it is simply a name for a pointer to a struct.
My C knowledge got very rusty over the years ;-)

Rick
```
Nov 26 2005
"Kris" <fu bar.com> writes:
```"Rick Noether" <richard.noether alum.com> wrote
{snip]
I'm guessing it's
C* y;

Hi Hasan,

In my example "C" itself is not a declared type,
I guess it is simply a name for a pointer to a struct.
My C knowledge got very rusty over the years ;-)

Then, it's not entirely clear what you're asking. In C, something prefixed
with "struct" is indeed of struct type. Was the original post of "struct C*
y;" a typo?
```
Nov 26 2005
Rick Noether <richard.noether alum.com> writes:
```On Sat, 26 Nov 2005 16:50:35 -0800 Kris wrote:

"Rick Noether" <richard.noether alum.com> wrote
{snip]
I'm guessing it's
C* y;

Hi Hasan,

In my example "C" itself is not a declared type,
I guess it is simply a name for a pointer to a struct.
My C knowledge got very rusty over the years ;-)

Then, it's not entirely clear what you're asking. In C, something prefixed
with "struct" is indeed of struct type. Was the original post of "struct C*
y;" a typo?

Hi Chris,

no, not a typo.

And yes, B.y is a pointer to a struct type. But that
struct type isn't declared anywhere. When you are going
to assign a pointer to some concrete struct Z to B.y you'd have
to cast it to C* (or struct C*), of course. When retrieving
the value of B.y you'd have to cast it back to Z* (hence you
need to know what was put in B.y).

It's a horrible design and I don't see any value in it. I even
don't know if it's valid C, but it seems to work (at least on VC6).
Now I think that my initial conjecture (void*) can't be improved
upon.

Thanks,
Rick
```
Nov 26 2005
"Kris" <fu bar.com> writes:
```"Rick Noether" <richard.noether alum.com> wrote
And yes, B.y is a pointer to a struct type. But that
struct type isn't declared anywhere. When you are going
to assign a pointer to some concrete struct Z to B.y you'd have
to cast it to C* (or struct C*), of course. When retrieving
the value of B.y you'd have to cast it back to Z* (hence you
need to know what was put in B.y).

It's a horrible design and I don't see any value in it. I even
don't know if it's valid C, but it seems to work (at least on VC6).
Now I think that my initial conjecture (void*) can't be improved
upon.

Oh, right. Then void* is the right thing, unless you decide to use classes
(where the C* would instead be a reference to some base-class).
```
Nov 26 2005
Rick Noether <richard.noether alum.com> writes:
```On Sat, 26 Nov 2005 17:54:34 -0800 Kris wrote:

Oh, right. Then void* is the right thing, unless you decide to use classes
(where the C* would instead be a reference to some base-class).