L
llothar
I need a function that iterates over an array, like this one:
int iterate_array (void* mem, size_t size, callback func)
{
char* p = (char*)mem;
while(size-- > 0) {
func(p);
p += size;
}
}
but i'm not sure how to get the value of 'size'. First of course was
the idea
int a[10];
iterate_array(a, sizeof(int), intfunc)
but what if the data is 6 byte? Then its up to the compiler (or
pragmas) it might be aligned to 8. How can i find this alignment. Will
a (sizeof(type[2])/2) expression always return the correct size
including alignment so that the generic iterator works ?
int iterate_array (void* mem, size_t size, callback func)
{
char* p = (char*)mem;
while(size-- > 0) {
func(p);
p += size;
}
}
but i'm not sure how to get the value of 'size'. First of course was
the idea
int a[10];
iterate_array(a, sizeof(int), intfunc)
but what if the data is 6 byte? Then its up to the compiler (or
pragmas) it might be aligned to 8. How can i find this alignment. Will
a (sizeof(type[2])/2) expression always return the correct size
including alignment so that the generic iterator works ?