Author: José Carlos
Date: 09:10:45 12/27/01
Go up one level in this thread
On December 27, 2001 at 11:50:28, Miguel A. Ballicora wrote:
>On December 27, 2001 at 11:19:35, José Carlos wrote:
>
>>On December 27, 2001 at 10:20:58, Miguel A. Ballicora wrote:
>>
>>>On December 27, 2001 at 09:02:00, José Carlos wrote:
>>>
>>>>
>>>> When things like these happen, I don't know whether it is the compiler that
>>>>doesn't work or I'm losing my mind. Yesterday I added this piece of code:
>>>>
>>>>for (i=0;i<PosActual->NumPeonesB;i++)
>>>>{
>>>> cCol=Columna(g_iPL_PB[i]);
>>>> cFil=Fila(g_iPL_PB[i]);
>>>> if (cFil>Retrasado(uPeonesB[cCol]))
>>>>uPeonesB[cCol]=(ParteAvanzada(uPeonesB[cCol]))|(unsigned int)(cFil);
>>>> if (cFil<Avanzado(uPeonesB[cCol]))
>>>>uPeonesB[cCol]=(cFil<<16)|ParteRetrasada(uPeonesB[cCol]);
>>>>}
>>>>for (i=0;i<PosActual->NumPeonesN;i++);
>>>>{
>>>> cCol=Columna(g_iPL_PN[i]);
>>>> cFil=Fila(g_iPL_PN[i]);
>>>> if (cFil<Retrasado(uPeonesN[cCol]))
>>>>uPeonesN[cCol]=(ParteAvanzada(uPeonesN[cCol]))|(unsigned int)(cFil);
>>>> if (cFil>Avanzado(uPeonesN[cCol]))
>>>>uPeonesN[cCol]=(cFil<<16)|ParteRetrasada(uPeonesN[cCol]);
>>>> i++;
>>>>}
>>>>
>>>> which fills two lists with information for pawn eval. When I run it, then it
>>>>performed an unhandled exception. I traced it and, to my surprise, when
>>>>initializing i in the second loop (exactly after executing the second for), the
>>>>value of i was 8!!!
>>>
>>>if PosActual->NumPeonesN is 7, when the first loop finishes i should be 8.
>>
>> Nope. It is 8 _after_ executing the sencond 'for' with F10.
>
>Ok, now I understand. Tracing sometimes is tricky when all the optimizations
>are 'ON'. Did you try with all the optimizations 'OFF'?. It looks like i was not
>initilialized "yet" but the important thing is that i has the right value the
>first time is needed.
>Try this in the second loop with the optimizations ON:
>
> for (i=0;i<PosActual->NumPeonesN;i++)
> {
> if (i < 0 || i >= PosActual->NumPeonesN)
> printf("n\Error, i=%d\n",i);
> exit(EXIT_FAILURE);
> }
> printf("trace i: %d\n",i);
> ...
>
> }
>
>I still do not understand why you do i++ at the end of the second loop.
>As far as I can see, that will skip several variables to be initialized.
>You should be able to see it with printf("trace i:...
>I wonder if that is the problem.
>
>Saludos,
>Miguel
>
>
>>
>>>I do not see anything wrong with that. The loop breaks when
>>>i<PosActual->NumPeonesN is no longer true, in other words, 8 or bigger.
>>>
>>>> I changed i for other variable; same thing. I tried to loop from
>>>>PosActual->NumPeonesN-1 down to zero; then i got a very big value instead of 7
>>>>-there were 8 pawns- (i is an integer).
>>>
>>>I'd like to see the actual loop control, if you have
>>>for (i=PosActual->NumPeonesN-1; i>=0; i--)
>>>then the loop breaks when i is lower than 0, i.e. -1.
>>>What kind of integer is i? unsigned? if that is true -1 underflows and goes to
>>>the maximum positive number that you gan get. The loop will never end and can
>>>create all sort of troubles that you can imagine.
>>>The other possibility is that you look at i as unsigned in the debugging session
>>>giving you a big number.
>>
>> i is signed int.
>>
>>>In the second loop there are things that I do not understand:
>>>
>>>for (i=0;i<PosActual->NumPeonesN;i++);
>>> /* ^
>>> * |
>>> * I do not think you intended to add this semicolon here!!!!
>>> */
>>
>> It is a typo made when removing comments to post it here. Not in my code.
>>
>> José C.
>>
>>>{
>>> cCol=Columna(g_iPL_PN[i]);
>>> cFil=Fila(g_iPL_PN[i]);
>>> if (cFil<Retrasado(uPeonesN[cCol]))
>>> uPeonesN[cCol]=(ParteAvanzada(uPeonesN[cCol]))|(unsigned int)(cFil);
>>> if (cFil>Avanzado(uPeonesN[cCol]))
>>> uPeonesN[cCol]=(cFil<<16)|ParteRetrasada(uPeonesN[cCol]);
>>>
>>> /* Why you update i here at the end if you do it at the top? */
>>>
>>> i++;
>>>
>>>}
>>>
>>>I hope this helped.
>>>
>>>Saludos,
>>>Miguel
>>>
>>>
>>>> Finally, I had to do a 'while' instead of a 'for' and it worked perfectly.
>>>> Can anyone tell me if I'm doing something wrong in the above code?
>>>>
>>>> Thanks in advance.
>>>>
>>>> José C.
Hola Miguel, parece ser que yo estaba equivocado, y tenía realmente el ; desde
el principio. Hice varios cambios y, probablemente, pensé que no había estado
desde el principio, y que lo introduje después.
En todo caso, el i++ es otro error de transcrición pues, al cambiar a while,
puse el incremento ahí en lugar de en la línea del while para estar seguro de
que el compilador no se liaba.
Gracias de todos modos.
In english: It was my mistake and I apologyze for it.
José C.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.