Warning: pointer of type 'void *' used in subtraction

c

Solution

Additions and subtractions with pointers work with the size of the pointed type:

int* foo = 0x1000;
foo++;
// foo is now 0x1004 because sizeof(int) is 4

Semantically speaking, the size of `void` should be zero, since it doesn't represent anything. For this reason, pointer arithmetic on `void` pointers should be illegal.

However, for several reasons, `sizeof(void)` returns 1, and arithmetic works as if it was a `char` pointer. Since it's semantically incorrect, you do, however, get a warning.

To suppress the warning, use `char` pointers.

Problem

Although it runs correctly, the following results in the aforementioned compiler warning: ``` return ((item - (my->items))/(my->itemSize)); ``` 'item' is a 'void *'; 'my->items' is a 'void *'; 'my->itemSize' is an 'int' Casting 'item' and 'my->items' as an 'int *' caused the program to run improperly. What is the best way to remove the warning?

Original source