Re: Linux printf funny
- From: Paul Burke <trash@xxxxxxxxxx>
- Date: Tue, 27 Feb 2007 13:22:24 +0000
Stef wrote:
Is this a win32 console application or an old DOS application?
It was W32 console, compiled with VC++6.
It does not sound like a windows/linux problem, but more like a
programming error. So please show us the code.
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "WinTypes.h"
#include "ftd2xx.h"
#include "ADC.h"
int TareWeight = 0; // ADC reading at no- load
double ScaleFactor = 1.0; // Bridge scale factor
double ReadWeight(void)
{
char buff[100];
double fweight; // Float version of weight
int Weight; // Weight as returned by ADC
Weight= ADCConvert();
fweight= (double)(Weight - TareWeight) * ScaleFactor;
sprintf( buff, "%08x - %08x -> %9.3f", Weight, TareWeight, fweight);
MessageBox( 0,buff,"Conversion Result",0);
return fweight;
}
MessageBox() is just a function that displays the strings supplied, and is in fact a replacement for the Windows message box as in the program's earlier incarnation as a windows GUI program before it got converted to console (don't ask!).
Here's the console output:
Conversion Result
000087bf - 000087bf -> 0.000
Conversion Result
000087bf - 000087bf -> 0.000
Conversion Result
000087bf - 000087bf -> 0.000
Conversion Result
000087bf - 000087bf -> 0.000
Conversion Result
000087c0 - 000087bf -> 1.000
Conversion Result
000087bf - 000087bf -> 0.000
Conversion Result
000087c0 - 000087bf -> 1.000
Conversion Result
000087bf - 000087bf -> nan
Conversion Result
000087c0 - 000087bf -> nan
Conversion Result
000087bf - 000087bf -> nan
"nan" then remains sticky until I restart the program. You'll notice that the int readings are much the same as when the output is correct!
I know I found some errors in old DOS (turbo C) test programs when I
ported them to new versions of compilers (windows or linux). These
programs worked normally using the old compiler but failed using a
newer one. All the errors where my own (beginners)fault: uninitialized
vars, wrong format specifiers, near/far pointer stuff etc.
I could believe that better if it didn't work for the first few readings.
Paul Burke
.
- Follow-Ups:
- Re: Linux printf funny
- From: tbroberg_nospam@xxxxxxxx
- Re: Linux printf funny
- From: tbroberg_nospam@xxxxxxxx
- Re: Linux printf funny
- From: D.
- Re: Linux printf funny
- From: Boudewijn Dijkstra
- Re: Linux printf funny
- From: Peter Dickerson
- Re: Linux printf funny
- References:
- Linux printf funny
- From: Paul Burke
- Re: Linux printf funny
- From: Stef
- Linux printf funny
- Prev by Date: Re: Linux printf funny
- Next by Date: Re: Linux printf funny
- Previous by thread: Re: Linux printf funny
- Next by thread: Re: Linux printf funny
- Index(es):