Marcelo Tosatti wrote:
The void pointer case in here its being done math on without any problem. What is the
problem with void pointer math
There is a problem regarding the C standard. The semantics of 'void *' are well defined
and only allow for limited use. Basically, you can cast any pointer to and from 'void *',
but nothing else.
Pointer math says that 'p+n' means "add to 'p' the value 'n*s' where 's' is the size
on the element that 'p' points to". A 'void *' does not have a defined element size
until it is cast. So, ANSI specifically does not allow any arithmetics on 'void *'.
Some compilers are forgiving and will invent an element size of '1' and allow the
math. We should not rely on such improper usage.