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



> Rouat manu wrote:
> > (from main:)
> >   char buffer[32];

> > this works - but the original code was:
> >   static char buffer[10];
> Note: the problem occurs when data=N_A 

But, has convert_to_char been invoked earlier, when data != N_A ?
If so, you might be suffering from buffer overflow.

Also, the two versions of the code use the data segment differently -
the original version has a static array (in the data seg), where the
newer version allocates it as a local variable. Also, there's a different
number and content for the format strings for sprintf.

Like I was saying, if you are experiencing "random" corruption to the data
seg of your program, any change to the data seg layout will (probably)
result in different variables (of different parts of a structure) being
corrupted, resulting in different behaviour.

I can't see anything wrong with convert_to_char BTW, other than buffer
being a bit on the small side. According to the Sun C answerbook, the
maximum double value is 1.7976931348623157E+308 - more than twice the
length of your original "buffer".

> > (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?)

You could use MAXFLOAT (I can't see anything resembling 'MAXDOUBLE' in
/usr/include/math.h, BTW).

Don't know the semantics of your data either - would it be possible to
define that a negative number means N/A?

Also, if you have a specific range, you could define that anything *greater
than* a particular limit (e.g. a million) means N/A.

In general, take care when using the == operator between floating-point
values - float and double are not accurate, only approximations (although
there ARE some values that can be represented exactly). Rounding error
can make some comparisons unreliable - particularly == and !=

The history of computing is littered with the bodies of people who forgot
about rounding error, e.g.

  Sear Sir,
  Your outstanding balance is $0.00
  If this is not paid within FIVE days, we will instigate legal action.

:-)

Allan



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