www.digitalmars.com         C & C++   DMDScript  

c++.dos.32-bits - Pointer Incrementation Problem - DAYSAGOF.C

reply Paul <Paul_member pathlink.com> writes:
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
parent "Walter" <walter digitalmars.com> writes:
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