c - Error dereferencing pointer to incomplete type and I can't figure out why -
i've went thru material here , can't seem spot error. i've created structs used , when trying manipulate them error. advice appriciated!
these structs defined in kdarray.c
struct sp_kdarray_t { sppoint* points; int** sorted; int rows; int size; }; struct sp_kdarrays_t { spkdarray kdleft; int leftsize; int rightsize; spkdarray kdright; };
and in kdarray.h have:
typedef struct sp_kdarray_t* spkdarray; typedef struct sp_kdarrays_t* spkdarrays;
now when try manipulate them ( recursively building tree ) in following function:
kdtreenode recursivetreebuild(spkdarray kdarr, int size, sp_tree_split_method spkdtreesplitmethod, int splittingdimension) { int split; kdtreenode result; result = (kdtreenode)malloc(sizeof(kdtreenode)); if (result == null) { sploggerprinterror("memory allocation error", __file__, __func__, __line__); return null; } if (size == 1) { result -> dim = -1; result -> val = -1; result -> left = null; result -> right = null; result -> data = spkdarraycopypoint(kdarr, 0); if (result -> data == null) { sploggerprinterror("memory allocation error", __file__, __func__, __line__); return null; } } else { spkdarrays subtrees; subtrees = spkdarraysplit(kdarr, splittingdimension); if (subtrees == null) return null; result -> dim = splittingdimension; result -> val = spkdarraygetmedianvaluebydimension(kdarr, splittingdimension); result -> data = null; switch (spkdtreesplitmethod) { case max_spread: split = spkdarraygethighestspread(kdarr); if (split < 0) return null; break; case random: srand(time(null)); split = rand() % spkdarraygetdimensions(kdarr); break; case incremental: split = splittingdimension + 1; break; } result -> left = recursivetreebuild(subtrees -> kdleft, subtrees -> leftsize, spkdtreesplitmethod, split); result -> right = recursivetreebuild(subtrees -> kdright, subtrees -> rightsize, spkdtreesplitmethod, split); } return result; }
i "dereferencing error" on :
result -> left = recursivetreebuild(subtrees -> kdleft, subtrees -> leftsize, spkdtreesplitmethod, split); result -> right = recursivetreebuild(subtrees -> kdright, subtrees -> rightsize, spkdtreesplitmethod, split);
thanks in advance!
your error happens because compiler cannot find definition of struct
. definition there, in wrong file or in wrong position in file. don't give details on layout of project cannot sure of details...
for example, following code trigger same error:
typedef struct foo_t* foo; void something1(foo p) { p->whatever; // error: incomplete type! } struct foo_t // type definition { int whatever; }; void something2(foo p) { p->whatever; // ok: type complete }
so should move definition of structs before function, or maybe header file itself.
or if want structs work opaque types, don't want publicly define them, usual way write public header declarations , private header definitions.
Comments
Post a Comment