This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

vsprintf float bug in GCC(?)


Hi,

I'm having a BIG problem trying to vsprintf float values.
Firstly I should mention that I am compiling for the H8/300 system using gcc
version 2.7-91q1 (yes it's old - nothing I can do about that just yet).

I have a function called AlphaPrintf which prints to a 16-char long display,
as such:

void AlphaPrintf(char *String, ...)
{
 char AlphaBuf[32];
 va_list VarListPtr;

 va_start(VarListPtr,String);
 vsprintf(AlphaBuf,String,VarListPtr);

 AlphaBuf[17] = '\0';
 PrintOnDisplay(AlphaBuf);    /* will print until the null is reached (duh!)
*/
}

I wish to be able to vsprintf a precision value (10.3f) , obtained from
dividing a long int with a
short int, cast to a double like so:

long int LongIntValue;
short int ShortIntValue;

float FloatVar1 = LongIntValue/(double)ShortIntValue;

and I am passing AlphaPrintf this:

AlphaPrintf("%10.3f",FloatVar1);

This works fine when FloatVar1 is zero. When non-zero, the system "crashes"
in vsprintf (and clobbers memory on the system!).

Does anyone know why? This works fine under another version of gcc I have
for another system (ancient version egcs-2.91.66, and no can't I port it
either yet).

I am most greatful for any help, it's driving me insane.

Regards,
Edward Byard








Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]