K
kamran
Hi
I was wondering if it is possible to recast a pointer in C ?
What I mean in detail is that I have compressed data coming from
an instrument. These are mostly sample differences from the
previous sample value. If there has been a small change in the
value of the new sample compared with a previous one, then
only one byte is enough to represent that value. If slightly
greater difference between the two sample value, data is
represented with two bytes and 3 bytes for even larger and
so on.
Now I have a pointer which is declared void :
(void *sample_difference)
and want to recast it to the appropriate type eg. (short *).
But it doesn't work. The compiler complains about a void pointer
can not point to another type. So I use "realloc" to try to
recast the pointer and no change is taking place. The pointer still
remains a void and the resulting value assignment is wrong.
I want to avoid to declare four different variables for
different sample values. Is it possible to only have one
variable and then recast it to the proper type ?
Thanks in advance
Kamran
I was wondering if it is possible to recast a pointer in C ?
What I mean in detail is that I have compressed data coming from
an instrument. These are mostly sample differences from the
previous sample value. If there has been a small change in the
value of the new sample compared with a previous one, then
only one byte is enough to represent that value. If slightly
greater difference between the two sample value, data is
represented with two bytes and 3 bytes for even larger and
so on.
Now I have a pointer which is declared void :
(void *sample_difference)
and want to recast it to the appropriate type eg. (short *).
But it doesn't work. The compiler complains about a void pointer
can not point to another type. So I use "realloc" to try to
recast the pointer and no change is taking place. The pointer still
remains a void and the resulting value assignment is wrong.
I want to avoid to declare four different variables for
different sample values. Is it possible to only have one
variable and then recast it to the proper type ?
Thanks in advance
Kamran