Re: [gtk-list] Re: Heisenberg was right?



Allan Black wrote:

> 
> Of all the types of bug that I've had to track down, the one that goes
> away when you insert a print statement is the worst of all!

I know what you mean!


> Now: the bad news :-(
> 
> There is a good (or bad?) chance that the piece of code which contains the
> bug is nowhere near the code where the program crashes. What can happen is,
> a corrupt pointer corrupts another pointer, which corrupts another pointer,
> ...... eventually, you use one of the corrupted pointers and crash.

I this case I think it's not too bad - I've replaced and simplified
the code that I suspect creates the trouble, and the bug apparently
dissapeared - here is the code:

(from main:)

  char buffer[32];
  sprintf (buffer, "%g", p.w);
  gtk_entry_set_text (GTK_ENTRY (w_entry),buffer);
  sprintf (buffer, "%g", p.l);
  gtk_entry_set_text (GTK_ENTRY (l_entry),buffer);

this works - but the original code was:

  gtk_entry_set_text (GTK_ENTRY (w_entry),convert_to_char(p.w));  
  gtk_entry_set_text (GTK_ENTRY (l_entry),convert_to_char(p.l)); 

and:

char *convert_to_char(double data)
{
  char *c;
  static char buffer[10];
  
  sprintf (buffer, "%g", data);
  if(data==N_A)
    sprintf (buffer, "N/A"); 
    c=buffer;
    /* printf("buffer:%g\n",data); */
    
  return c;  
}

It's the convert_to_char function which is screwy, obviously.

Any ideas to implement this differently?

(note: #define N_A 6e66 - bad idea I guess....Is there a reserved
symbol or number in C to describe infinity or 'No result' or
anything?)

Regards,


manu




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]