www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Dynamic array of pointers to opaque structs

reply "Johan F." <jaffe1 gmail.com> writes:
I'm fiddling around with SDL2 using Derelict3, and I'm trying to 
make an array of SDL_Texture pointers, like so:

     SDL_Texture*[] frames;
     ... make texture ...
     frames ~= texture;

However, this yields the following error:

/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture is forward 
referenced when looking for 'toHash'
/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture is forward 
referenced when looking for 'opCmp'
/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture is forward 
referenced when looking for 'toString'
/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture unknown size
/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture no size yet for 
forward reference
/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture unknown size
/Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
Error: struct derelict.sdl2.types.SDL_Texture no size yet for 
forward reference

At line 1865 in types.d is the opaque struct declaration

     struct SDL_Texture;

The program compiles and works fine if I change this line to

     struct SDL_Texture {};

This seems weird to me. Why is making an array of _pointers_ to 
SDL_Texture dependant on how the SDL_Texture struct is declared? 
Also, is simply adding {} the right way of fixing it, or will 
that possibly break something else?
Jun 05 2013
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 06/05/2013 10:34 PM, Johan F. wrote:
 I'm fiddling around with SDL2 using Derelict3, and I'm trying to make an
 array of SDL_Texture pointers, like so:

      SDL_Texture*[] frames;
      ... make texture ...
      frames ~= texture;

 However, this yields the following error:

 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture is forward referenced when
 looking for 'toHash'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture is forward referenced when
 looking for 'opCmp'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture is forward referenced when
 looking for 'toString'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture unknown size
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture no size yet for forward reference
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture unknown size
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): Error:
 struct derelict.sdl2.types.SDL_Texture no size yet for forward reference

 At line 1865 in types.d is the opaque struct declaration

      struct SDL_Texture;

 The program compiles and works fine if I change this line to

      struct SDL_Texture {};

 This seems weird to me. Why is making an array of _pointers_ to
 SDL_Texture dependant on how the SDL_Texture struct is declared? Also,
 is simply adding {} the right way of fixing it, or will that possibly
 break something else?
It is a compiler bug, but we cannot confirm it unless you provide a minimal example that triggers it.
Jun 05 2013
parent "Johan F." <jaffe1 gmail.com> writes:
On Wednesday, 5 June 2013 at 20:37:27 UTC, Timon Gehr wrote:
 On 06/05/2013 10:34 PM, Johan F. wrote:
 I'm fiddling around with SDL2 using Derelict3, and I'm trying 
 to make an
 array of SDL_Texture pointers, like so:

     SDL_Texture*[] frames;
     ... make texture ...
     frames ~= texture;

 However, this yields the following error:

 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture is forward referenced 
 when
 looking for 'toHash'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture is forward referenced 
 when
 looking for 'opCmp'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture is forward referenced 
 when
 looking for 'toString'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture unknown size
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture no size yet for forward 
 reference
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture unknown size
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error:
 struct derelict.sdl2.types.SDL_Texture no size yet for forward 
 reference

 At line 1865 in types.d is the opaque struct declaration

     struct SDL_Texture;

 The program compiles and works fine if I change this line to

     struct SDL_Texture {};

 This seems weird to me. Why is making an array of _pointers_ to
 SDL_Texture dependant on how the SDL_Texture struct is 
 declared? Also,
 is simply adding {} the right way of fixing it, or will that 
 possibly
 break something else?
It is a compiler bug, but we cannot confirm it unless you provide a minimal example that triggers it.
This triggers it (2.063): struct something; int main() { something*[] stuff; something* a; stuff ~= a; return 0; }
Jun 05 2013
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 5 June 2013 at 20:34:17 UTC, Johan F. wrote:
     struct SDL_Texture;
Just guessing here, what happens if you make that extern(C) struct SDL_Texture; ?
 Also, is simply adding {} the right way of fixing it, or will 
 that possibly break something else?
This shouldn't break anything since it is just adding RTTI info to D (opCmp, toHash, etc, are members of the D TypeInfo for this struct. why they are required in this case is beyond me). It doesn't change the actual core of the code, which are still just pointers.
Jun 05 2013
parent reply "Johan F." <jaffe1 gmail.com> writes:
On Wednesday, 5 June 2013 at 20:38:08 UTC, Adam D. Ruppe wrote:
 On Wednesday, 5 June 2013 at 20:34:17 UTC, Johan F. wrote:
    struct SDL_Texture;
Just guessing here, what happens if you make that extern(C) struct SDL_Texture; ?
It doesn't change anything.
 Also, is simply adding {} the right way of fixing it, or will 
 that possibly break something else?
This shouldn't break anything since it is just adding RTTI info to D (opCmp, toHash, etc, are members of the D TypeInfo for this struct. why they are required in this case is beyond me). It doesn't change the actual core of the code, which are still just pointers.
Ok, thanks. I'll just add {} then, until the bug(?) gets fixed.
Jun 05 2013
parent reply "Namespace" <rswhite4 googlemail.com> writes:
It's not a bug:
http://dblog.aldacron.net/forum/index.php?topic=820.0
Jun 05 2013
parent reply "Johan F." <jaffe1 gmail.com> writes:
On Wednesday, 5 June 2013 at 20:51:03 UTC, Namespace wrote:
 It's not a bug:
 http://dblog.aldacron.net/forum/index.php?topic=820.0
Hmm, that thread seems to address something else? I'm talking about simply making an array of pointers to opaque structs, which
Jun 05 2013
parent "Namespace" <rswhite4 googlemail.com> writes:
Oh ok. I thought you suspect a bug in Derelict.
Jun 05 2013
prev sibling parent "Mike Parker" <aldacron gmail.com> writes:
On Wednesday, 5 June 2013 at 20:34:17 UTC, Johan F. wrote:
 I'm fiddling around with SDL2 using Derelict3, and I'm trying 
 to make an array of SDL_Texture pointers, like so:

     SDL_Texture*[] frames;
     ... make texture ...
     frames ~= texture;

 However, this yields the following error:

 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture is forward 
 referenced when looking for 'toHash'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture is forward 
 referenced when looking for 'opCmp'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture is forward 
 referenced when looking for 'toString'
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture unknown size
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture no size yet for 
 forward reference
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture unknown size
 /Users/jaffe1/prog/Derelict3/import/derelict/sdl2/types.d(1865): 
 Error: struct derelict.sdl2.types.SDL_Texture no size yet for 
 forward reference

 At line 1865 in types.d is the opaque struct declaration

     struct SDL_Texture;

 The program compiles and works fine if I change this line to

     struct SDL_Texture {};

 This seems weird to me. Why is making an array of _pointers_ to 
 SDL_Texture dependant on how the SDL_Texture struct is 
 declared? Also, is simply adding {} the right way of fixing it, 
 or will that possibly break something else?
For anyone stumbling across this thread in the future, there's a report for this in bugzilla[1]. It's an issue in the compiler with the handling of opaque structs. [1] http://d.puremagic.com/issues/show_bug.cgi?id=10451
Aug 28 2013