I was wondering how qsort works with the combination of typeSize and void* input. I want to do arithmetic, but I'm not totally sure how to work this out...I'm thinking I could do a switch( typeSize ) and then convert to the appropriate type based on that, but I wouldn't be able to distinguish the difference between an int and an unsigned int.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
/*
I want the input to be void*..not long.
*/
void hmmm( void *v, size_t typeSize )
{
/*
void*.c: In function `hmmm':
void*.c:7: warning: dereferencing `void *' pointer
void*.c:7: error: invalid use of void expression
*/
*v = 5;
}
int main( void )
{
int n = 4;
char c = 4;
hmmm( &n, sizeof( n ) );
hmmm( &c, sizeof( c ) );
assert( n == 5 );
assert( c == 5 );
return 0;
}