Pointer type casting altering unintended memory
<pre><code>#define ARRAY_SIZE 20

float DataSource[ARRAY_SIZE];

void Read(unsigned char const *Source, unsigned char *Destination, unsigned long DataSize)
{
  for ( unsigned long i = 0; i &lt; DataSize; i++)
  {
    *(Destination + i*DataSize) = *(Source + i*DataSize);
  }
}

void fun()
{
  int Index;
  float Dest;

  for ( Index = 0; Index &lt; ARRAY_SIZE; Index++ )
  {
    Read((unsigned char *)&amp;DataSource[Index], (unsigned char *)&amp;Dest, sizeof(DataSource[Index]));
  }
}
</code></pre>

<p>I'm having an issue with the above code where upon calling Read(), my Index variable gets overwritten and I am certain the ugly pointer casting is the culprit, but I'm having trouble understanding exactly what is happening here.</p>

<p>The unsigned char pointer types are mandatory because the above code is intended to simulate some driver level software and maintain the same prototype.</p>

<p>Can someone help me to understand the issue here? All the above code is changeable except for the prototype of Read().</p>
