Function to foreach over an array
Well, it's unavoidably quite complex to use, you need to provide 3 arguments to describe the array (start, size, element_size) and a function accepting a single element as a void*-argument:
Writing the loop manually is far simpler.

To top it of, you cannot pass any context to your callback, meaning it can only work on global state. That's all kinds of unfortunate.

Now, let's look at your implementation:
You are far too cast-happy.


The casts to int are wrong, SIZE_MAX can be bigger than INT_MAX. Anyway they are superfluous because yes you can use a size_t for pointer-arithmetic.
The cast to void* is superfluous, it would be implicitly converted.


Incorporating that all gives you:

#include &lt;stddef.h&gt;
void foreach_array(
    void* array,
    size_t size,
    size_t bytes_per_element,
    void (*callback)(void* context, void* element),
    void* context
) {
    for(char* iter = array; iter &lt; (char*)array + size; iter += bytes_per_element)
        callback(context, iter);
}