digitalmars.D - Help?
- Manu (18/18) Aug 30 2013 struct MyStruct; // <- forward declared (opaque type, never defined)
- Dicebot (2/2) Aug 30 2013 Is it even legal D? I though forward declaration was allowed only
- Manu (2/4) Aug 30 2013
- Johannes Pfau (7/8) Aug 30 2013 Sometimes
- Andrej Mitrovic (9/16) Aug 30 2013 Yeah opaque structs have their bugs, I currently use this workaround in ...
- Manu (5/13) Aug 31 2013 Yeah, that's no good. That certainly opens up more problems.
- Mike Parker (5/7) Aug 30 2013 My understanding of extern(C) is that it just affects the calling
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/22) Aug 30 2013 The effect on Variant:
- Mike Parker (6/32) Aug 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10451
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...
Aug 30 2013
Is it even legal D? I though forward declaration was allowed only for "extern(C)" stuff.
Aug 30 2013
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.
Aug 30 2013
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
On 8/30/13, Johannes Pfau <nospam example.com> wrote:Am Sat, 31 Aug 2013 04:09:10 +1000 schrieb Manu <turkeyman gmail.com>: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.So should I extern(C) the forward declaration?Sometimes --- struct MyStruct {} ---
Aug 30 2013
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>: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.So should I extern(C) the forward declaration?Sometimes --- struct MyStruct {} --- is used as a workaround, but that may have other issues.
Aug 31 2013
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
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
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