www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Help?

reply Manu <turkeyman gmail.com> writes:
--001a11c2e81c3a1a4404e52d8bbc
Content-Type: text/plain; charset=UTF-8

struct MyStruct; // <- forward declared (opaque type, never defined)

MyStruct*[] arrayOfPointers;

arrayOfPointers ~= null; // appending doesn't work
arrayOfPointers = new MyStruct*[n]; // or just allocating the array doesn't
work either

Complains:
1>code.d(84): Error: struct MyStruct is forward referenced when looking for
'toHash'
1>code.d(84): Error: struct MyStruct is forward referenced when looking for
'opCmp'
1>code.d(84): Error: struct MyStruct is forward referenced when looking for
'toString'
1>code.d(84): Error: struct MyStruct unknown size
1>code.d(84): Error: struct MyStruct no size yet for forward reference
1>code.d(84): Error: struct MyStruct unknown size
1>code.d(84): Error: struct MyStruct no size yet for forward reference

What's the go here?
Why would it need any of that information? It's just a pointer...

--001a11c2e81c3a1a4404e52d8bbc
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">struct MyStruct; // &lt;- forward declared (opaque type, n=
ever defined)<div><br></div><div>MyStruct*[] arrayOfPointers;</div><div><br=
</div><div>arrayOfPointers ~=3D null; // appending doesn&#39;t work</div><=

arrayOfPointers =3D new MyStruct*[n]; // or just allocating the array doesn= &#39;t work either<br></div><div><br></div><div>Complains:</div><div>1&gt;c= ode.d(84): Error: struct=C2=A0MyStruct is forward referenced when looking f= or &#39;toHash&#39;<br> </div><div><div>1&gt;code.d(84): Error: struct=C2=A0MyStruct=C2=A0is forwar= d referenced when looking for &#39;opCmp&#39;</div><div>1&gt;code.d(84): Er= ror: struct=C2=A0MyStruct=C2=A0is forward referenced when looking for &#39;= toString&#39;</div> <div>1&gt;code.d(84): Error: struct=C2=A0MyStruct=C2=A0unknown size</div><d= iv>1&gt;code.d(84): Error: struct=C2=A0MyStruct=C2=A0no size yet for forwar= d reference</div><div>1&gt;code.d(84): Error: struct=C2=A0MyStruct=C2=A0unk= nown size</div><div>1&gt;code.d(84): Error: struct=C2=A0MyStruct=C2=A0no si= ze yet for forward reference</div> </div><div><br></div><div>What&#39;s the go here?</div><div>Why would it ne= ed any of that information? It&#39;s just a pointer...</div></div> --001a11c2e81c3a1a4404e52d8bbc--
Aug 30 2013
next sibling parent "Dicebot" <public dicebot.lv> writes:
Is it even legal D? I though forward declaration was allowed only 
for "extern(C)" stuff.
Aug 30 2013
prev sibling next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 08/30/2013 10:27 AM, Manu wrote:
 struct MyStruct; // <- forward declared (opaque type, never defined)

 MyStruct*[] arrayOfPointers;

 arrayOfPointers ~= null; // appending doesn't work
 arrayOfPointers = new MyStruct*[n]; // or just allocating the array doesn't
 work either

 Complains:
 1>code.d(84): Error: struct MyStruct is forward referenced when looking for
 'toHash'
 1>code.d(84): Error: struct MyStruct is forward referenced when looking for
 'opCmp'
 1>code.d(84): Error: struct MyStruct is forward referenced when looking for
 'toString'
 1>code.d(84): Error: struct MyStruct unknown size
 1>code.d(84): Error: struct MyStruct no size yet for forward reference
 1>code.d(84): Error: struct MyStruct unknown size
 1>code.d(84): Error: struct MyStruct no size yet for forward reference

 What's the go here?
 Why would it need any of that information? It's just a pointer...

The effect on Variant: http://d.puremagic.com/issues/show_bug.cgi?id=10766 Ali
Aug 30 2013
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--089e013c701a88bc5c04e52e1e67
Content-Type: text/plain; charset=UTF-8

So should I extern(C) the forward declaration?


On 31 August 2013 03:45, Dicebot <public dicebot.lv> wrote:

 Is it even legal D? I though forward declaration was allowed only for
 "extern(C)" stuff.

--089e013c701a88bc5c04e52e1e67 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">So should I extern(C) the forward declaration?</div><div c= lass=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On 31 August 2013 0= 3:45, Dicebot <span dir=3D"ltr">&lt;<a href=3D"mailto:public dicebot.lv" ta= rget=3D"_blank">public dicebot.lv</a>&gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">Is it even legal D? I though forward declara= tion was allowed only for &quot;extern(C)&quot; stuff.<br> </blockquote></div><br></div> --089e013c701a88bc5c04e52e1e67--
Aug 30 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Sat, 31 Aug 2013 04:09:10 +1000
schrieb Manu <turkeyman gmail.com>:

 So should I extern(C) the forward declaration?

Sometimes --- struct MyStruct {} --- is used as a workaround, but that may have other issues.
Aug 30 2013
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/30/13, Johannes Pfau <nospam example.com> wrote:
 Am Sat, 31 Aug 2013 04:09:10 +1000
 schrieb Manu <turkeyman gmail.com>:

 So should I extern(C) the forward declaration?

Sometimes --- struct MyStruct {} ---

Yeah opaque structs have their bugs, I currently use this workaround in dlibgit: struct MyStruct { disable this(); disable this(this); } This should be close to an opaque type, although .sizeof might still work, so it's not 100% opaque.
Aug 30 2013
prev sibling next sibling parent "Mike Parker" <aldacron gmail.com> writes:
On Friday, 30 August 2013 at 17:28:12 UTC, Manu wrote:
 struct MyStruct; // <- forward declared (opaque type, never 
 defined)

 MyStruct*[] arrayOfPointers;

 arrayOfPointers ~= null; // appending doesn't work
 arrayOfPointers = new MyStruct*[n]; // or just allocating the 
 array doesn't
 work either

 Complains:
 1>code.d(84): Error: struct MyStruct is forward referenced when 
 looking for
 'toHash'
 1>code.d(84): Error: struct MyStruct is forward referenced when 
 looking for
 'opCmp'
 1>code.d(84): Error: struct MyStruct is forward referenced when 
 looking for
 'toString'
 1>code.d(84): Error: struct MyStruct unknown size
 1>code.d(84): Error: struct MyStruct no size yet for forward 
 reference
 1>code.d(84): Error: struct MyStruct unknown size
 1>code.d(84): Error: struct MyStruct no size yet for forward 
 reference

 What's the go here?
 Why would it need any of that information? It's just a 
 pointer...

http://d.puremagic.com/issues/show_bug.cgi?id=10451 A couple of other forward-ref bugs relating to opaque structs have been recently fixed in git master. If I knew where to look or what to do, I'd fix this one myself. It's an ongoing source of bug reports for Derelict and is bugging the hell out of me.
Aug 30 2013
prev sibling next sibling parent "Mike Parker" <aldacron gmail.com> writes:
On Friday, 30 August 2013 at 17:45:14 UTC, Dicebot wrote:
 Is it even legal D? I though forward declaration was allowed 
 only for "extern(C)" stuff.

My understanding of extern(C) is that it just affects the calling convention (and, I assume, name mangling) of functions/function pts and has no impact on types. I haven't seen anything in the documentation to tell me otherwise.
Aug 30 2013
prev sibling parent Manu <turkeyman gmail.com> writes:
--001a11c33676f09db704e547b24d
Content-Type: text/plain; charset=UTF-8

On 31 August 2013 04:59, Johannes Pfau <nospam example.com> wrote:

 Am Sat, 31 Aug 2013 04:09:10 +1000
 schrieb Manu <turkeyman gmail.com>:

 So should I extern(C) the forward declaration?

Sometimes --- struct MyStruct {} --- is used as a workaround, but that may have other issues.

Yeah, that's no good. That certainly opens up more problems. The point is that it is an undefined struct, and it can only be used to type a pointer. It's pretty much impossible to extern to a lot of C code if this doesn't work properly. --001a11c33676f09db704e547b24d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">On 31 August 2013 04:59, Johannes Pfau <span dir=3D"ltr">&= lt;<a href=3D"mailto:nospam example.com" target=3D"_blank">nospam example.c= om</a>&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_= quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-= left:1px #ccc solid;padding-left:1ex"> Am Sat, 31 Aug 2013 04:09:10 +1000<br> schrieb Manu &lt;<a href=3D"mailto:turkeyman gmail.com">turkeyman gmail.com= </a>&gt;:<br> <div class=3D"im"><br> &gt; So should I extern(C) the forward declaration?<br> <br> </div>Sometimes<br> ---<br> struct MyStruct {}<br> ---<br> is used as a workaround, but that may have other issues.<br> </blockquote></div><br></div><div class=3D"gmail_extra">Yeah, that&#39;s no= good. That certainly opens up more problems.</div><div class=3D"gmail_extr= a">The point is that it is an undefined struct, and it can only be used to = type a pointer. It&#39;s pretty much impossible to extern to a lot of C cod= e if this doesn&#39;t work properly.</div> </div> --001a11c33676f09db704e547b24d--
Aug 31 2013