NO

Author Topic: Array assignment  (Read 3145 times)

alinsdau

  • Guest
Array assignment
« on: December 07, 2010, 06:00:50 PM »
I have ran into a bug with loops and array assignment with type casting.  The program below crashes.  The debugger is set to full information and optimizations are disabled.  The compiler version is 6.00.4
Any suggestions you have will be appreciated!

******CODE******

#define VGN_POINTS   8

int main(int argc, char *argv[])
{
   int loop;   // Generic loop variable
   float vgn_multiplier;
long VGN_normalized_i[VGN_POINTS]; //!< Normalized VGN measurement according to DS-S4-1-3-1_A(PR2)
long VGN_data[VGN_POINTS];

   
   // Perform vgn_multiplier code once, as the value doesn't change during
   //  the normalization FOR loop
      vgn_multiplier = 0.84f;

   VGN_data[0] =  6;
   VGN_data[1] = 226;
   VGN_data[2] = 302;
   VGN_data[3] = 445;
   VGN_data[4] = 608;
   VGN_data[5] = 784;
   VGN_data[6] = 988;
   VGN_data[7] = 1213;

   for(loop = 0; loop<VGN_POINTS; loop++)
   {
      VGN_normalized_i[loop] = (long)(vgn_multiplier * (float)VGN_data[loop]);
   }   
    return 0;
}

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Array assignment
« Reply #1 on: December 09, 2010, 10:37:50 AM »
Your code works with Pelles c 5.0. With Pelles C 6.0 and Pelles C 6.50 rc2 the compiler tries to store two different values in the same register. The return value of ftol and the index for storing the result are in EAX.
With Pelles C 6.50 RC3 you can avoid this problem with using:
Code: [Select]
volatile int loop; // With volatile the compiler should generate code which reads each time the value from memoryThis works for RC3 with and without optimizations.
best regards
 Alex ;)

jaikanth123

  • Guest
Re: Array assignment
« Reply #2 on: April 20, 2011, 08:03:26 AM »

Your cipher works with Pelles c 5.0. With Pelles C 6.0 and Pelles C 6.50 rc2 the compiler tries to abundance two altered ethics in the aforementioned register. The acknowledgment amount of ftol and the basis for autumn the aftereffect are in EAX.