sh3, newlib, and sprintf

Steve Goodrich
Mon Nov 8 14:13:00 GMT 1999

I have an Hitachi HS7709 eval board that I am trying to get up and running on. I
am having problems with the sprintf function. sprintf seems to work unless I use
a floating point parameter, i.e. "sprintf(ca, "%f", a);" where ca is a 32 byte
character array and a is a double. 

I am using newlib 1.8.1, gcc 2.95.2, binutils-2.9.1. If I run the program under
the debugger, I can see that the floating point math is working correctly but
after the sprintf function, nothing has been done to the target char array. If I
change the format string to "%d" and use an integer param instead, it works

I have attached the code for a small test program below. I know it is not the
most efficient code but we are trying to put together a benchmark for floating
point performance. my_putchar is just the putchar routine from the docs for the
eval board. Does anyone have any suggestions?




#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "fsrentry.h"

void sendstr(const char *cp);

int main()
    double a = 0.0;
    char ca[32];
    while(a <= 2.0*M_PI)
        a += M_PI/8.0;
        sprintf(ca, "%e", a);
    return 0;

void sendstr(const char *cp)

# My Makefile. I have tried compiling with and without -mhitachi
NAME    = examples

CC      = sh-rtems-hms-gcc
CXX     = sh-rtems-hms-g++
AS      = sh-rtems-hms-as

CFLAGS =  -m3 -gstabs -O4   -mhitachi 

LDFLAGS = -mhitachi  -m3 -gstabs -T$(LINKER_SCRIPT) -Wl,-Map=$(basename $@).map
\ -L/home/steveg/bin/crossgcc/sh-rtems-hms/sh-rtems-hms/lib/m2 -lm

all: sertest.txt

sertest.txt: sertest.x
    sh-rtems-hms-objcopy -O srec sertest.x sertest.txt

sertest.o: sertest.c
    $(CC) $(CFLAGS) -Wall $< -c -o $@ 

fsrjump.o: fsrjump.s
    $(AS)   -g $< -o $@

sertest.x: sertest.o fsrjump.o
    $(CC) $(LDFLAGS) -o $@ $? 

# This clean rule can only be used with a properly setup Cygwin environment
# or Linux. Sorry.

.PHONY : clean
    rm -f *.x *.o *.map core *.d

.PHONY : distclean
    rm -f *.x *.o *.map core *.d *.\$$\$$\$$ *.d@

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

More information about the crossgcc mailing list