warning: dereferencing `void *' pointer

From: Pushkar Pradhan (pushkar_at_gri.msstate.edu)
Date: 12/14/03


Date: Sat, 13 Dec 2003 21:24:16 -0600

I have some functions which take as i/p a buffer (it can be float, char,
or 16 bit, int etc.). The result is another o/p buffer, its type is also
flexible (it could be a float, char etc.).

I try to pass both as "void *buf" so that it can accept any data type.
But since I access the buffer and try to assign its elements to another
I get compile errors (I have pasted at the end).

Now my question is how can I pass the i/p and o/p buffers as args to the
function without hardcoding the data type, someone earlier suggested to
pass another argument which tells the type, e.g.
myfunction(void * buf, 1, ...) 1 may indicate that buf is char type, 2
means 16 bit etc.

But that means having if .. else's inside the function to do the same
thing. Is there any other way?
Maybe this is not possible in C.
Pushkar Pradhan

resample.c: In function `resample':
resample.c:26: warning: dereferencing `void *' pointer
resample.c:26: warning: dereferencing `void *' pointer
resample.c:26: invalid use of void expression
resample.c:35: warning: dereferencing `void *' pointer
resample.c:35: warning: dereferencing `void *' pointer
resample.c:35: invalid use of void expression