Hi everyone, sorry to ask another question that seems so simple, but I really can't figure this one out. I'm reading about Void Pointers in "The C++ Language Tutorial" and I can't understand what this function does:
That is badly formatted, here is the code in a more readable format with lines commented:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void increase (void* data, int psize)
{
if ( psize == sizeof(char) ) // check if the type 'data' is pointing to is char
{
char* pchar; // create a new pointer to char
pchar=(char*)data; // assign it to the position pointed by data
++(*pchar); // increase the value at that position (this will affect the first byte at data)
}
elseif (psize == sizeof(int) ) // do the same thing but with int
{
int* pint;
pint=(int*)data;
++(*pint); // the result of this depends on the size of an int and on the endianness of the computer
}
}