NO

Author Topic: Printing some integers causes strange numbers on rpt unless printf done first!  (Read 2680 times)

aronoffs

  • Guest
Hello,

I developed a financial calculator for my own use which does numerous calcs, then creates a spreadsheet-like report.  The amounts that print come from global arrays of integers.  I've had this program working for 5 years.

I recently upgraded to version 6 of Pelles C and also made a few tweaks to the program.  Now the report is showing a few of the columns with incorrect,  very large numbers, nothing like what should have been calculated. 

Since my logic seemed correct, I decided to display values that make up the calculations for these bad columns of data.  These displays showed that all variables that make up the calculations and the integers that receive the values to print all look fine.  Not only that, the report now shows the values for these columns correctly!!  No more strange, large numbers.

Further testing has shown that the numbers appear correctly on the report ONLY IF these display's are in the program.

Anybody with ideas on this?

Thanks.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
What happen if you compile your original program with optimizations turned off? Is result Ok?
Try also to add the specifier "volatile" to the variables that carry wrong values.
I.e.
  int a; -> volatile int a;
If these two options, on the original software without printouts, give you good result maybe there is a bug in compiler optimizations. In this case please try to isolate the smallest piece of software that exhibits the problem and post it in bug reports section. This will help Pelle, when he will be back, to diagnose the compiler.
« Last Edit: October 26, 2009, 08:16:39 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide