Re: Linux printf funny
- From: "Arlet" <usenet+5@xxxxxxxxxx>
- Date: 27 Feb 2007 10:26:05 -0800
On Feb 27, 4:40 pm, Paul Burke <t...@xxxxxxxxxx> wrote:
Boudewijn Dijkstra wrote:
Looks like an optimization problem. The compiler is seeing a constant
where it shouldn't, and/or has modified the type of a variable to
double. Without seeing the code that deals with TareWeight, I'd guess
this is it. Try making it volatile.
Another possibility is a bug that modifies ScaleFactor, which BTW isn't
declared const.
I've found that it doesn't matter what the ADC reading is, and changing
ScaleFactor and TareWeight to constants doesn't change the behaviour. If
I run it as originally shown, it does 7 conversions before GDB shows
fweight as a nan (value 0x8000000000000). If I split out the
calculation, so that:
fweight = (Weight - xTareWeight);
fweight *= ScaleFactor;
it still does 7 printfs, but if I comment out the Scalefactor line, it
does 8 before nan shows up! It also behaves like this if I replace
variables ScaleFactor, Weight and TareWeight with explicit constant values.
Depending on the CPU you're using, the compiler may implement constant
doubles by creating a 'constant pool' in memory, and loading the
values from there.
My guess is that some other part of your program is corrupting memory,
and that after 7 or 8 iterations, the corruption has reached the code
or variables used in this function. There's nothing wrong with the
code you posted.
.
- Follow-Ups:
- Re: Linux printf funny
- From: tbroberg_nospam@xxxxxxxx
- Re: Linux printf funny
- References:
- Linux printf funny
- From: Paul Burke
- Re: Linux printf funny
- From: Stef
- Re: Linux printf funny
- From: Paul Burke
- Re: Linux printf funny
- From: Boudewijn Dijkstra
- Re: Linux printf funny
- From: Paul Burke
- Linux printf funny
- Prev by Date: Re: Linux printf funny
- Next by Date: Re: Internet Embedded
- Previous by thread: Re: Linux printf funny
- Next by thread: Re: Linux printf funny
- Index(es):