Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct DArray {
- int end;
- int max;
- size_t element_size;
- size_t expand_rate;
- void **contents;
- } DArray;
- typedef int (*DArray_compare) (const void *a, const void *b);
- int compare(const void *a, const void *b)
- {
- int i = (int)*a;
- int k = (int)*b;
- printf("%d %dn", i, k);
- return i - k;
- }
- error: operand of type 'void' where arithmetic or pointer type is required int i = (int)*a;
- int i = *(int*)a;
- // This one has more parens to make it really obvious what your intent is.
- int k = *((int*)b);
- // Cast b from a pointer to a void into a pointer to an int.
- int *X = (int*)b;
- // k = "what X is pointing to" or "the contents of X"
- int k = *X;
- typedef int (*DArray_compare) (const int *a, const int *b);
- int compare(const int *a, const int *b)
- {
- int i = *a;
- int k = *b;
- ...
- int compare(const void *a, const void *b)
- {
- const DArray *d1 = a;
- const DArray *d2 = b;
- if (d1->end < d2->end)
- return -1;
- else if (d1->end > d2->end)
- return +1;
- else if (d1->max < d2->max)
- return -1;
- else if (d2->max > d2->max)
- return +1;
- else
- return 0;
- }
- if (i < k)
- return -1;
- else if (i > k)
- return +1;
- else
- return 0;
Add Comment
Please, Sign In to add comment