Strange problem with "sprintf"

bperrybap:
RE: floating point patch

Bill,

I found that the sscanf function also needs to be patched!

Here is an updated script to do the entire patch:

#!/bin/bash
################################################################################
# fixfp - script to install floating point support into Arduino printf library
#
# open software - use, modify, distribute freely
#
# For more information, see this post:
# http://arduino.cc/forum/index.php/topic,124809.msg938573.html#msg938573
################################################################################

STATUS=0

## Exit if libc.a isn't here
test -e libc.a
if [ ${?} -ne 0 ]; then {
	echo "File 'libc.a' not found - exiting"
	exit 0
} fi

test -e libc.a.orig
let STATUS+=${?}

test -e vfprintf_flt.o
let STATUS+=${?}

test -e vfscanf_flt.o
let STATUS+=${?}

## Don't re-apply the patch (would ruin the backup libc.a)
if [ $STATUS -eq 0 ]; then {
	echo "Floating point patch already performed - exiting"
	exit 0
} else {
	cp libc.a libc.a.orig
	ar -dv libc.a vfprintf_std.o
	ar -dv libc.a vfscanf_std.o
	ar -xv libprintf_flt.a vfprintf_flt.o
	ar -xv libscanf_flt.a vfscanf_flt.o
	ar -rv libc.a vfprintf_flt.o
	ar -rv libc.a vfscanf_flt.o
	echo "Floating point patch installed."
} fi

(edit): If you are using a different OS and/or do not wish to patch your files, you may instead download [u]THIS[/u] package (a .ZIP file) which contains the patched versions of "libc.a". Then, locate the "libc.a" files in your Arduino distribution, rename all of them to something like "libc.a.backup" (to preserve the original), then copy the new "libc.a" files from the ZIP archive into your distribution.

Take note of the different versions for different processor directories. They must all go in the proper places!
Zipfile contents:

Archive: libc_all.zip
Length Name


581202 avr25/libc.a
584430 avr3/libc.a
584474 avr31/libc.a
581702 avr35/libc.a
580574 avr4/libc.a
581058 avr5/libc.a
581106 avr51/libc.a
581218 avr6/libc.a
581490 avrxmega5/libc.a
581650 avrxmega7/libc.a
583910 libc.a


6402814 11 files

You will now have full floating point support for the "sprintf" and "sscanf" functions.

NOTE that this updated library will cause your compiled sketches to be approximately 1500 bytes larger due to the floating point code. You may go back to the original library at any time simply by deleting the patched "libc.a" files and renaming your backups back to "libc.a".

Thanks to bperrybap for the original idea!

-- Roger