Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GSTcomparator problems
#1
So I am having some problems getting my compareGSTVAL function to work.

I have created a separate c file called gstval.c. In it there is a pointer to a display function, a free function, and a compare function. The display and free functions work as expected.

Every time I create a new node in my GST, I create a GSTVAL that stores a frequency and the inserted value. Then (still in the insertGST) I set the GSTVAL's display function to be equal to the GST display, and I do the same thing for free and compare. Again, free and display both work as intended. 

The compareGSTVAL bugs out on this line:

return gstval->compare(gstval->value, gstval2->value);

This should work, because the GSTVAL structure contains the correct compare function(the GST compare function, passed in when the GSTVAL was created.)
For example it never actually goes into the compareINTEGER function; I have tested it with printf statements and it is clear that it bugs out as soon as it reaches the line I posted.

Is there a better way to be doing this?

I tried putting a pointer to my GST tree in my GSTVAL class, but when I typed this: return gstval->gst->compare(gstval->value, gstval2->value);
It said that my gst->compare pointer was dereferencing an incomplete type (meaning the gst pointer inside my gstval.c is incomplete.) I really don't know what is wrong with this code.
Reply
#2
You should not have a separate gstv.c module since your GST values are private to your GST. The code you have in gstv.c should be in gst.c and declared static (meaning private).

You get the incomplete type because you made the GSTVAL public.

Print the address of the compare function "%p" in your GSTVAL constructor and in your GSTVAL comparator. They should match. Do they?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)