Q:

Managing different datatypes in C without code repetition

For handling different datatypes the following code does work.  However is there a better way of writing this without repeating the code for different datatypes?
in  = (unsigned char *) calloc(pixels, bpp);
out = (unsigned char *) calloc(pixels, bpp);

if (bpp == 1) 
 for (x = 0; x < pixels; x++)
  *(out + (x * bpp)) = *(in + (x * bpp));

if (bpp == 2) 
 for (x = 0; x < pixels; x++)
  *(short *)(out + (x * bpp)) = *(short *)(in + (x * bpp));

if (bpp == 4) 
 for (x = 0; x < pixels; x++)
  *(float *)(out + (x * bpp)) = *(float *)(in + (x * bpp));

if (bpp == 8) 
 for (x = 0; x < pixels; x++)
  *(double *)(out + (x * bpp)) = *(double *)(in + (x * bpp));               

Thanks for the responses so far and my apologies for my lack of clarity.  The above snippet of code was just an example of what I was trying to achieve. Supposing we want to rearrange the order of values for instance:
 for (x = 0; x < pixels; x++)
  *(out + (pixels - 1 - x) * bpp) = *(in + (x * bpp));

Here memcpy() would not help.  Basically I want to get rid of the repeated code for the different datatypes, so I can order the values any way I like for any datatype.

A:

Why not just use memcpy()?
memcpy(out, in, pixels * bpp);

