This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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

Re: problem while building arm vfp softfloat gcc


Robert Schwebel wrote:
Dan,

gcc-3.3.2 with glibc-2.3.2 seem to have problems with printf and
floating point anyway. Look at this test case:


----------8<----------
#include <stdio.h>

int main (void)
{
	float f = 1.0;
	double d = 1.0;
	long double ld = 1.0;
	
	printf ("Without cast:\n");
	printf ("float:\n");
	printf ("f : %f\nlf: %lf\nLf: %Lf\n", f, f, f);
	printf ("double:\n");
	printf ("f : %f\nlf: %lf\nLf: %Lf\n", d, d, d);
	printf ("long double:\n");
	printf ("f : %f\nlf: %lf\nLf: %Lf\n", ld, ld, ld);
	
	printf ("With cast:\n");
	printf ("float:\n");
	printf ("f : %f\nlf: %lf\nLf: %Lf\n", (float) f, (double) f, (long double) f);
	printf ("double:\n");
	printf ("f : %f\nlf: %lf\nLf: %Lf\n", (float) d, (double) d, (long double) d);
	printf ("long double:\n");
	printf ("f : %f\nlf: %lf\nLf: %Lf\n", (float) ld, (double) ld, (long double) ld);
	return 0;
}
----------8<----------

Compiled with vanilla Debian gcc-3.3.2 on x86:

$ gcc -W -Wall test.c -o test_float
test.c: In Funktion main:
test.c:11: Warnung: long double Format, double Argument (Argument 4)
test.c:13: Warnung: long double Format, double Argument (Argument 4)
test.c:15: Warnung: double Format, long double Argument (Argument 2)
test.c:15: Warnung: double Format, long double Argument (Argument 3)

$ ./test_float Without cast:
float:
f : 1.000000
lf: 1.000000
Lf: 0.000000
double:
f : 1.000000
lf: 1.000000
Lf: 0.000000
long double:
f : -0.000000
lf: 0.000000
Lf: 0.000000
With cast:
float:
f : 1.000000
lf: 1.000000
Lf: 1.000000
double:
f : 1.000000
lf: 1.000000
Lf: 1.000000
long double:
f : 1.000000
lf: 1.000000
Lf: 1.000000


Nice ;-)

I just looked at this again, and your test is ill-formed. The compiler warnings are serious. You can't use a %Lf with a float or double argument; it's just wrong.

Running it under Valgrind shows that yes, there is a problem in your test:

$ valgrind ./a.out
==15012== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==15012== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==15012== Using valgrind-2.0.0, a program supervision framework for x86-linux.
==15012== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==15012== Estimated CPU clock rate is 652 MHz
==15012== For more details, rerun with: -v
==15012==
Without cast:
float:
f : 1.000000
lf: 1.000000
==15012== Use of uninitialised value of size 10
==15012==    at 0x4028193B: __GI___printf_fp (in /lib/libc-2.3.2.so)
==15012==    by 0x4027E78D: _IO_vfprintf_internal (in /lib/libc-2.3.2.so)
==15012==    by 0x40286F61: _IO_printf (in /lib/libc-2.3.2.so)
==15012==    by 0x80483AC: main (in /home/dank/a.out)
Lf: 39056147575609589784034689511659250843882363222790321856005091224403645257710138702712820697908241251704901197028864206216643959792505667077624350898378859821
529724659055029729479899684017517792252021949173393587500015397278703511579423059685433335901505324259648458677898269910561853178031040488092009134514663344740739
667580476045119561834221258939059151035249473386229374374016016840769779904532804268503204969711181475899999708006605667158510040856950973242440125607644442538663
414177036017170147731212889071689037277123374551279497415090064477712900445936889712855796061610572552511183489164093673845423620309217638036839616014841616118641
956739235122024250453491298559246186629640706228476855004887600584807998397571778811336802262154645874092162762357966769351700724256199752322619833638105243178103
009616016192756102226001398264517783505589795191003904320757581503434934199416181199789342529393754974793383067624825655576744190771222576057682480679864082924830
563422089810870420909581793534579040868679487655644695310654625815004468913523643388941442224210549654491795954372703783760463701166364907117300374309573374572699
959506208104449154101508730439904608465553932144650757181752335704532063242703474941978215576415916410912894513371248798503196666437097907380643716853084823474051
536012188417859941887221069377010605362674884876453631486956026338511392067368367867787629544782512978595378967906628262933076668482181890467621726228217688628805
842556829953943769521588647696047890431324712760093146627207593944624325311597055896999160704754798328263695002213023272169817322822873260852690103996807596814331
930506661302920000769531486917074245260127219379929659625155350886986129581901084489190104194107184806998236089932660173024865229056683522961428982995563070551431
157531160552216914422949801318698041057560161286560610140262017446620874567751309968440127001061297113933477415086581816235570450480748640441041333301412128705400
081135235309760348932411613049491531983410978522305009278395402336017200011583311681887513528840337679202465792549502168976768013553737458696195662716023035081780
745821797360079001757881763790143166544303610153790500682052190746390482014356997211131414102304249945916859000745810659562296711183145472074956554616841108576934
519988084890616376474723348361046985916523516196805413915590380289837632147700359964431741397976309835458882643589720906054970935213861819290001371497956224498645
309981034020162336536761849178021485845909685357465316468586802974708219717583491975802963606850965363490963162838762540945045081019941748088236653414885943780132
533548133438940160053664459523227042782072363081324195221878492507167872012086348798270912980534402225870246767310957413523798591736155200147192300109506102828170
625883188144605816473140000439156324408629883103564305396079001314057588197047961057740212457639123584991107960131045041117665345342860145065045585616508903830801
553775735897431987376287446290251023761368220445071366783716545068797326873753386331042890301122296297899356676398455021542071084902633378251465719065235910013829
1244255791994242204316542840926487635151626124051051134126926379195535298815991841516948282299151865198315383043700285953865223610189217792.000000
double:
f : 1.000000
lf: 1.000000
==15012==
==15012== Use of uninitialised value of size 10
==15012==    at 0x4028193B: __GI___printf_fp (in /lib/libc-2.3.2.so)
==15012==    by 0x4027E78D: _IO_vfprintf_internal (in /lib/libc-2.3.2.so)
==15012==    by 0x40286F61: _IO_printf (in /lib/libc-2.3.2.so)
==15012==    by 0x80483DE: main (in /home/dank/a.out)
Lf: 39056147575609589784034689511659250843882363222790321856005091224403645257710138702712820697908241251704901197028864206216643959792505667077624350898378859821
529724659055029729479899684017517792252021949173393587500015397278703511579423059685433335901505324259648458677898269910561853178031040488092009134514663344740739
667580476045119561834221258939059151035249473386229374374016016840769779904532804268503204969711181475899999708006605667158510040856950973242440125607644442538663
414177036017170147731212889071689037277123374551279497415090064477712900445936889712855796061610572552511183489164093673845423620309217638036839616014841616118641
956739235122024250453491298559246186629640706228476855004887600584807998397571778811336802262154645874092162762357966769351700724256199752322619833638105243178103
009616016192756102226001398264517783505589795191003904320757581503434934199416181199789342529393754974793383067624825655576744190771222576057682480679864082924830
563422089810870420909581793534579040868679487655644695310654625815004468913523643388941442224210549654491795954372703783760463701166364907117300374309573374572699
959506208104449154101508730439904608465553932144650757181752335704532063242703474941978215576415916410912894513371248798503196666437097907380643716853084823474051
536012188417859941887221069377010605362674884876453631486956026338511392067368367867787629544782512978595378967906628262933076668482181890467621726228217688628805
842556829953943769521588647696047890431324712760093146627207593944624325311597055896999160704754798328263695002213023272169817322822873260852690103996807596814331
930506661302920000769531486917074245260127219379929659625155350886986129581901084489190104194107184806998236089932660173024865229056683522961428982995563070551431
157531160552216914422949801318698041057560161286560610140262017446620874567751309968440127001061297113933477415086581816235570450480748640441041333301412128705400
081135235309760348932411613049491531983410978522305009278395402336017200011583311681887513528840337679202465792549502168976768013553737458696195662716023035081780
745821797360079001757881763790143166544303610153790500682052190746390482014356997211131414102304249945916859000745810659562296711183145472074956554616841108576934
519988084890616376474723348361046985916523516196805413915590380289837632147700359964431741397976309835458882643589720906054970935213861819290001371497956224498645
309981034020162336536761849178021485845909685357465316468586802974708219717583491975802963606850965363490963162838762540945045081019941748088236653414885943780132
533548133438940160053664459523227042782072363081324195221878492507167872012086348798270912980534402225870246767310957413523798591736155200147192300109506102828170
625883188144605816473140000439156324408629883103564305396079001314057588197047961057740212457639123584991107960131045041117665345342860145065045585616508903830801
553775735897431987376287446290251023761368220445071366783716545068797326873753386331042890301122296297899356676398455021542071084902633378251465719065235910013829
1244255791994242204316542840926487635151626124051051134126926379195535298815991841516948282299151865198315383043700285953865223610189217792.000000
long double:
f : -0.000000
lf: 0.000000
Lf: 0.000000
With cast:
float:
f : 1.000000
lf: 1.000000
Lf: 1.000000
double:
f : 1.000000
lf: 1.000000
Lf: 1.000000
long double:
f : 1.000000
lf: 1.000000
Lf: 1.000000



--
My technical stuff: http://kegel.com
My politics: see http://www.misleader.org for examples of why I'm for regime change

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


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