NO

Author Topic: Debugger error on array assignment to array  (Read 5149 times)

alinsdau

  • Guest
Debugger error on array assignment to array
« on: December 07, 2010, 02:32:19 AM »
I am having trouble with the Pelles C debugger.  I've written code that writes one typecast array to another that should work.  However, the debugger throws an Access Violation on the 5th cycle of the 2nd for loop (below) and doesn't write to the array correctly at all.  Is there something weird here?  I've expanded the for loops for easier isolation of the problem.  The second for loop increments the variable loop to 6 instead of stepping through as expected.  Note - The hard-coded values are in there just for debugging.

Thanks for any input...

// CODE

#define VGN_POINTS   8

float VGN_normalized_f[VGN_POINTS];
long VGN_normalized_i[VGN_POINTS];
long VGN_data[VGN_POINTS];

int main(int argc, char *argv[])
{
   int loop; 
   float vgn_multiplier;
   
   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_f[loop] = vgn_multiplier * (float)VGN_data[loop];
   }   

   for(loop = 0; loop<VGN_POINTS; loop++)
   {
   VGN_normalized_i[loop] =  (long)(VGN_normalized_f[loop]);
   }   

    return 0;
}

alinsdau

  • Guest
Re: Debugger error on array assignment to array
« Reply #1 on: December 07, 2010, 02:37:23 AM »
I am running compiler version 6.00.4.
Debugging is set to:
Compiler Debug info: full
Assembler debug info: full
Linker debug info:  codeview & COFF format

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Debugger error on array assignment to array
« Reply #2 on: December 07, 2010, 04:44:01 PM »
Optimization error in pocc 6.50.17 too?
Code: [Select]
  for(loop = 0; loop<VGN_POINTS; loop++)
  [00401050] 31C0                   xor             eax,eax
   {
VGN_normalized_f[loop] = vgn_multiplier * (float)VGN_data[loop];
  [00401052] D90500304000           fld             dword ptr [00403000]
  [00401058] DA0C8550454000         fimul           dword ptr [eax*4+VGN_data]
  [0040105F] D91C8590454000         fstp            dword ptr [eax*4+VGN_normalized_f]
  [00401066] 40                     inc             eax
  [00401067] 83F808                 cmp             eax,+8
  [0040106A] 7CE6                   jl              00401052
}

for(loop = 0; loop<VGN_POINTS; loop++)
  [0040106C] 31C0                   xor             eax,eax
{
VGN_normalized_i[loop] =  (long)(VGN_normalized_f[loop]);
  [0040106E] D9048590454000         fld             dword ptr [eax*4+VGN_normalized_f]
  [00401075] E816000000             call            ___ftol
  [0040107A] 89C2                   mov             edx,eax
  [0040107C] 89148570454000         mov             dword ptr [eax*4+VGN_normalized_i],edx
  [00401083] 40                     inc             eax
  [00401084] 83F808                 cmp             eax,+8
  [00401087] 7CE5                   jl              0040106E
}  
Watch EAX register.
« Last Edit: December 07, 2010, 06:18:53 PM by timovjl »
May the source be with you

alinsdau

  • Guest
Re: Debugger error on array assignment to array
« Reply #3 on: December 07, 2010, 05:38:58 PM »
I did see that the EAX wasn't consistent.  I trurned off all optimizations and ran into the same problem.  Is there a known issue with the code generator in rev 6.00.4?  This is a significant problem.

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Debugger error on array assignment to array
« Reply #4 on: December 09, 2010, 11:08:52 AM »
I did see that the EAX wasn't consistent.  I trurned off all optimizations and ran into the same problem. 
With Pelles C 6.50 rc3 you can avoid this problem by using:
Code: [Select]
volatile int loop;
best regards
 Alex ;)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Debugger error on array assignment to array
« Reply #5 on: December 09, 2010, 12:29:58 PM »
alinsdau I suggest to move to RC#3 version of the compiler because the former versions are known to be buggy.
Anyway there is something strange, this seems the same problem related to __ftol (see http://forum.pellesc.de/index.php?topic=3244.0), but in my compiler, version 6.50.17 (which is RC#3) there is no error!  :o
The compiler use ecx registers to hold the loop counter, and works correctly whichever optimization I choose.
For me POCC 6.50.17 RC#3 works well  ???
« Last Edit: December 09, 2010, 12:35:48 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide