I'm fairly sure the answer to this is 'no, don't be stupid', but as they say, there are no stupid questions (only stupid people asking them).
I want to calculate the offset of an array. I have a void *
handle to it and the sizeof(element)
. I don't have an x*
pointer (where x
is the type of the element).
Is there any way I can cast the void *
pointer to one of a given size so I can do pointer arithmetic based on that size? At the moment I'm casting to a char *
(assuming a char
is 1 byte*) and then multiplying the sizeof value by the offset. If I could somehow cast the pointer, then I could just use the array syntax, which would be cleaner.
As I say, I'm 99% sure this isn't possible and I'm basically asking for language-level type representation which C doesn't have. But worth an ask.
*And I'd rather not because it's not always true.