www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Array of struct pointers error

reply "Szymon Gatner" <noemail gmail.com> writes:
I want to keep a list of pointers-to-C-struct but this line:

   cpBody* cpBodies_[];
   cpBodies_ ~= cpBodyNew(0, 0);

gives:

Error	1	Error 42: Symbol Undefined 
_D5dchip6cpBody6cpBody11__xopEqualsFKxS5dchip6cpBody6cpBodyKxS5d
hip6cpBody6cpBodyZb 
(bool dchip.cpBody.cpBody.__xopEquals(ref 
const(dchip.cpBody.cpBody), ref 
const(dchip.cpBody.cpBody)))	D:\projects\DeeDee\

where cpBodyNew(float, float) returns cpBody*, which is struct.

Interestingly, when I wrap cpBopy* into a another struct (or a 
Tuple) like so:

struct Body
{
   private cpBody* bdy_;
}

there is no problem to do

Body bodies[];
bodies ~= Body(cpBodyNew(0, 0));

which I use as a workaround. I am using DMD 2.065.
Feb 26 2014
next sibling parent reply "Tobias Pankrath" <tobias pankrath.net> writes:
On Wednesday, 26 February 2014 at 09:56:39 UTC, Szymon Gatner 
wrote:
 I want to keep a list of pointers-to-C-struct but this line:

   cpBody* cpBodies_[];
 which I use as a workaround. I am using DMD 2.065.
cpBody*[] cpBodies;
Feb 26 2014
parent reply "Szymon Gatner" <noemail gmail.com> writes:
On Wednesday, 26 February 2014 at 10:01:53 UTC, Tobias Pankrath 
wrote:
 On Wednesday, 26 February 2014 at 09:56:39 UTC, Szymon Gatner 
 wrote:
 I want to keep a list of pointers-to-C-struct but this line:

  cpBody* cpBodies_[];
 which I use as a workaround. I am using DMD 2.065.
cpBody*[] cpBodies;
Is there a different array declaration syntax for pointers? Anyway, same error.
Feb 26 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Szymon Gatner:

 Is there a different array declaration syntax for pointers?
There is not. But the D-style syntax is preferred for arrays. Bye, bearophile
Feb 26 2014
prev sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Szymon Gatner:

 I want to keep a list of pointers-to-C-struct but this line:
Please reduce your code as much as possible, and show the whole compilable reduced buggy program here. Bye, bearophile
Feb 26 2014
parent reply "Szymon Gatner" <noemail gmail.com> writes:
On Wednesday, 26 February 2014 at 10:59:39 UTC, bearophile wrote:
 Szymon Gatner:

 I want to keep a list of pointers-to-C-struct but this line:
Please reduce your code as much as possible, and show the whole compilable reduced buggy program here. Bye, bearophile
That would be just it: import dchip.all; void main() { cpBody* bodies[]; auto b = cpBodyNew(0, 0); bodies ~= b; } where dchip is pulled using dub. As described earlier, wrapping cpBody* in another struct or Tuple works.
Feb 26 2014
next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Szymon Gatner:

 That would be just it:

 import dchip.all;

 void main()
 {
   cpBody* bodies[];
   auto b = cpBodyNew(0, 0);
   bodies ~= b;
 }

 where dchip is pulled using dub. As described earlier, wrapping 
 cpBody* in another struct or Tuple works.
Now you have to remove all imports from the code :-) Bye, bearophile
Feb 26 2014
parent "Szymon Gatner" <noemail gmail.com> writes:
On Wednesday, 26 February 2014 at 11:21:37 UTC, bearophile wrote:
 Szymon Gatner:

 That would be just it:

 import dchip.all;

 void main()
 {
  cpBody* bodies[];
  auto b = cpBodyNew(0, 0);
  bodies ~= b;
 }

 where dchip is pulled using dub. As described earlier, 
 wrapping cpBody* in another struct or Tuple works.
Now you have to remove all imports from the code :-) Bye, bearophile
I just pulled cpBody struct definition on top of main() and now it compiles... So I guess this means that when importin main() does not see full cpBody struct definition? But why does that even matter? It is just pointers being stored.
Feb 26 2014
prev sibling parent reply "Tobias Pankrath" <tobias pankrath.net> writes:
On Wednesday, 26 February 2014 at 11:07:44 UTC, Szymon Gatner 
wrote:
 On Wednesday, 26 February 2014 at 10:59:39 UTC, bearophile 
 wrote:
 Szymon Gatner:

 I want to keep a list of pointers-to-C-struct but this line:
Please reduce your code as much as possible, and show the whole compilable reduced buggy program here. Bye, bearophile
That would be just it: import dchip.all; void main() { cpBody* bodies[]; auto b = cpBodyNew(0, 0); bodies ~= b; } where dchip is pulled using dub. As described earlier, wrapping cpBody* in another struct or Tuple works.
No offense: But an example should be reduced until we can compile it without additional code, excluding phobos and maybe dub'ed projects. But then you would need to provide a package.json. I do think that's related to [1] and a bug with dmd 2.065. Does it work with 2.064? [1] http://www.reddit.com/r/programming/comments/1ytfc5/d_2065_released_with_396_fixes_and_improvements/cfnmkih
Feb 26 2014
parent "Szymon Gatner" <noemail gmail.com> writes:
On Wednesday, 26 February 2014 at 11:22:00 UTC, Tobias Pankrath 
wrote:
 On Wednesday, 26 February 2014 at 11:07:44 UTC, Szymon Gatner 
 wrote:
 On Wednesday, 26 February 2014 at 10:59:39 UTC, bearophile 
 wrote:
 Szymon Gatner:

 I want to keep a list of pointers-to-C-struct but this line:
Please reduce your code as much as possible, and show the whole compilable reduced buggy program here. Bye, bearophile
That would be just it: import dchip.all; void main() { cpBody* bodies[]; auto b = cpBodyNew(0, 0); bodies ~= b; } where dchip is pulled using dub. As described earlier, wrapping cpBody* in another struct or Tuple works.
No offense: But an example should be reduced until we can compile it without additional code, excluding phobos and maybe dub'ed projects. But then you would need to provide a package.json.
Sorry for not doing that. I replied in other response.
 I do think that's related to [1] and a bug with dmd 2.065. Does 
 it work with 2.064?

 [1] 
 http://www.reddit.com/r/programming/comments/1ytfc5/d_2065_released_with_396_fixes_and_improvements/cfnmkih
It certainly seems related as it is also about opCmp() but why is it only linker error and not compilation error?
Feb 26 2014