c++.dos.32-bits - Pointer Incrementation Problem - DAYSAGOF.C
Hi Walter, I have a problem with my pointer not incrementing smoothly, one record to the next. (see code below) While stepping through an array and watching in the data/object window, the following is happening. (Imagine array numbered 1 to 10) records 1,2,0,0,5,6,0,0,9,10....etc. So it misses some records yet catches up, later. This is causing my pointer to go past the end of the array and my program crash. race_ctr = 0; /* find this race */ while( this_race_ptr->ref != this_run_ptr->ref && race_ctr < race_file_size ) { race_ctr++; this_race_ptr++; } The program compiles with no errors or warning messages. It's target is Windows 95 and Console. Maybe a clue here: When trying to locate the bug, after assigning "this_race_ptr" to the "racemem_ptr" (allocated memory) the following increment statements had no effect. this_race_ptr++; (and the following) this_race_ptr += (race_file_size); Yet on other pointers in the same location (after declaration, not in while loop) they work as they should? I have attached the source file. Any help very much appreciated. Paul begin 0644 DAYSAGOF.C M+RH 4')O9W)A;2!T;R!C86QC=6QA=&4 =&AE(&1A>7-A9V\ 96QA<'-E9"!F M;W( 96%C:"!R=6YN97( :6X <G5N;F5R<R!F:6QE+ T*("` 1&5S:6=N960 M9F]R($9L870 <V5A<V]N<R!O;FQY('5S:6YG(%-M87)T<VEG($1A=&$ ,3$O M=&1L:6(N:#X-"B-I;F-L=61E(#QC;VYI;RYH/ T*(VEN8VQU9&4 (FAO<G-E M("` 1DE,12`J<G5N;F5R7V9P*3L-"G-T<G5C="!R86-E<R`J(')A8V5S7V%L M;&]C*'-T<G5C="!R86-E<R`J<F%C96UE;5]P='(L;&]N9R`J<F%C97-I>F5? M<'1R+$9)3$4 *G)A8V5?9G`I.PT*=F]I9"!M96U?97)R;W(H8VAA<B`J(&9I M7V1A>7-A9V]?<'1R+"`J;&%S=%]D87ES86=O7W!T<CL-" T*:6YT(&UA:6XH M*0T*>PT*("` 1DE,12`J;F5W7V9P+`T*("` ("` ("`J<G5N;F5R7V9P+`T* M<F%C97, ("`J<F%C96UE;5]P='(L*G1H:7-?<F%C95]P='(L("IL87-T7W)A M="` ;F]?<')E=FEO=7-?<G5N(#T ,#L-" T*("` <G5N<VEZ95]P='( (#T M:6XB+")R8B(I.PT*("` <F%C97-?9G` (#T M,BYB:6XB+")R8B(I.PT*("` ;F5W7V9P("` (#T ;W!E;E]F:6QE*")R=6XP M;&]C*')U;FUE;5]P='(L<G5N<VEZ95]P='(L<G5N;F5R7V9P*3L-"B` (')A M8V5M96U?<'1R(#T <F%C97-?86QL;V,H<F%C96UE;5]P='(L<F%C97-I>F5? M<'1R+')A8V5S7V9P*3L-" T*("` =&AI<U]D87ES86=O7W!T<B`](&1A>7-? M='( *ST *')U;E]F:6QE7W-I>F4 +2`Q*3L ("` ("` ("` ("` ("`O*B!M M;W9E('1O(&5N9"!O9B!A<G)A>2`J+PT*("` ;&%S=%]R86Y?<'1R("`](')U M+2`R*3L-"B` ('1H:7-?<F%C95]P='( /2!R86-E;65M7W!T<CL-"B` (&QA M<W1?<F%C95]P='( /2!R86-E;65M7W!T<CL-" T*("`O*BHJ*BHJ*BHJ*BHJ M7W!T<B`K/2`H<F%C95]F:6QE7W-I>F4I.R`J+R` ("` ("` ("` ("` +RH M("` ("` ("`)("` ("` ("` ("` ("` ("` ("` ("` +RIF:6YD(&AO<G-E M<R!L87-T(')A8V4 *B\-"B` ("` =VAI;&4H(&QA<W1?<F%N7W!T<BT^:&]R M<V4 (3T =&AI<U]R=6Y?<'1R+3YH;W)S90T*("` ("` ("` ("` ("`F)B!L M;E]P='(M/FAO<G-E(#T]('1H:7-?<G5N7W!T<BT^:&]R<V4 *0T*("` ("![ M(')A8V4 *B\-"B` ("` ("` =VAI;&4H('1H:7-?<F%C95]P='(M/G)E9B`A M/2!T:&ES7W)U;E]P='(M/G)E9 T*("` ("` ("` ("` ("`F)B!R86-E7V-T M<B`\(')A8V5?9FEL95]S:7IE("D ("` ("` ("` ("`O*BHJ*BHJ*BHJ*BHJ M("` <F%C95]C='(K*SL ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` M8W1R(#T ,#L M('=H:6QE*"!L87-T7W)A8V5?<'1R+3YR968 (3T ;&%S=%]R86Y?<'1R+3YR M968-"B` ("` ("` ("` ("` ("8F(')A8V5?8W1R(#P <F%C95]F:6QE7W-I M9&%Y<U]A<G)A>2`J+PT*("` ("` ("!W:&EL92 *G1H:7-?9&%Y<V%G;U]P M(&1A>7-?87)R87D *B\-"B` ("` ("` =VAI;&4H("IL87-T7V1A>7-A9V]? M<'1R("$](&QA<W1?<F%C95]P='(M/F1A=&4 *0T*("` ("` ("` ("` ("` M>7-A9V]?<'1R(#P M("!T:&ES7W)U;E]P='(M/F1A>7-A9V\ /2`H=&AI<U]D87ES86=O7W!T<B`M M*SL-"B` ("!T:&ES7W)U;E]P='(M+3L-"B` ("!L87-T7W)A;E]P='( /2!T M9&%Y<V%G;U]P='( /2!D87ES7V%R<F%Y.PT*("` (&QA<W1?9&%Y<V%G;U]P M='( /2!D87ES7V%R<F%Y.PT*("` ('1H:7-?<F%C95]P='( /2!R86-E;65M M7W!T<CL-"B` ("!L87-T7W)A8V5?<'1R(#T M:7IE("H <VEZ96]F*'-T<G5C="!R=6YN97)S*2PQ+&YE=U]F<"D (3T ,2D- M"B` ('L-"B` ("` ('!R:6YT9B B17)R;W( =W)I=&EN9R!T;R!F:6QE+BXN M17AI=&EN9R(I.PT*("` ("` 97AI=" Q*3L-"B` ('T-" T*("` 9G)E92AR M<V4H;F5W7V9P*3L-"B` (&9C;&]S92AR=6YN97)?9G`I.PT*("` 9F-L;W-E M*')A8V5S7V9P*3L-"B` ('!R:6YT9B B7&Y0<F]G<F%M(%-U8V-E<W-F=6PB M*3L-"B` ('!R:6YT9B B7&Y%;G1E<B!A(&YU;6)E<B!T;R!E>&ET("T^("(I M<E]A;&QO8RAS=')U8W0 <G5N;F5R<R`J<G5N;65M7W!T<BP ;&]N9R`J<G5N M(&9I;&5?<VEZ93L-" T*("!I9B *&9S965K*')U;FYE<E]F<"PH;&]N9RD M;6%L;&]C*&9I;&5?<VEZ92`J('-I>F5O9BAS=')U8W0 <G5N;F5R<RDI.PT* M*")R=6YN97)S(&9I;&4B*3L-" T*("!I9B 9G)E860H<G5N;65M7W!T<BQS M:7IE;V8H<W1R=6-T(')U;FYE<G,I+&9I;&5?<VEZ92QR=6YN97)?9G`I("$] M(&9I;&5?<VEZ92D-"B` ("` <F5A9%]E<G)O<B B<G5N;F5R<R!F:6QE(BD[ M=')U8W0 <F%C97, *G)A8V5M96U?<'1R+&QO;F< *G)A8V5S:7IE7W!T<BQ& M24Q%("IR86-E7V9P*0T*>PT*("!L;VYG(&9I;&5?<VEZ93L-" T*("!I9B M:6QE7W-I>F4 /2!F=&5L;"AR86-E7V9P*2]S:7IE;V8H<W1R=6-T(')A8V5S M<G5C="!R86-E<R`J*2!M86QL;V,H9FEL95]S:7IE("H <VEZ96]F*'-T<G5C M86-E;65M7W!T<BQS:7IE;V8H<W1R=6-T(')A8V5S*2QF:6QE7W-I>F4L<F%C M95]F<"D (3T 9FEL95]S:7IE*0T*("` ("!R96%D7V5R<F]R*")R86-E<R!F M<B`J(&9I;&5?;F%M92D-"GL-"B` ('!R:6YT9B B365M;W)Y(&%L;&]C871I M;VX 97)R;W( )7, +BXN17AI=&EN9R(L9FEL95]N86UE*3L-"B` (&5X:70H M"GL-"B` ('!R:6YT9B B1E-E96L 97)R;W( :6X 9FEL92`E<RXN+D5X:71I M97)R;W(H8VAA<B`J(&9I;&5?;F%M92D-"GL-"B` ('!R:6YT9B B1FEL92!R M96%D:6YG(&5R<F]R("5S+BXN17AI=&EN9R(L9FEL95]N86UE*3L-"B` (&5X ` end
Nov 10 2003
I'd start by loading the program up with printf's to trace its execution. "Paul" <Paul_member pathlink.com> wrote in message news:booboh$r0i$1 digitaldaemon.com...Hi Walter, I have a problem with my pointer not incrementing smoothly, one record to the next. (see code below) While stepping through an array and watching in the data/object window, the following is happening. (Imagine array numbered 1 to 10) records 1,2,0,0,5,6,0,0,9,10....etc. So it misses some records yet catches up, later. This is causing my pointer to go past the end of the array and my program crash. race_ctr = 0; /* find this race */ while( this_race_ptr->ref != this_run_ptr->ref && race_ctr < race_file_size ) { race_ctr++; this_race_ptr++; } The program compiles with no errors or warning messages. It's target is Windows 95 and Console. Maybe a clue here: When trying to locate the bug, after assigning "this_race_ptr" to the "racemem_ptr" (allocated memory) the following increment statements had no effect. this_race_ptr++; (and the following) this_race_ptr += (race_file_size); Yet on other pointers in the same location (after declaration, not in while loop) they work as they should? I have attached the source file. Any help very much appreciated. Paul
Nov 10 2003