Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
August 30, 2013 Help? | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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... |
August 30, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | Is it even legal D? I though forward declaration was allowed only for "extern(C)" stuff. |
August 30, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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 |
August 30, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot Attachments:
| 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.
>
|
August 30, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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.
|
August 30, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | 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.
|
August 31, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | 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. |
August 31, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | 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.
|
September 01, 2013 Re: Help? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau Attachments:
| 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.
|
Copyright © 1999-2021 by the D Language Foundation