EmbDev.net

Forum: ARM programming with GCC/GNU tools why doesn't sprintf( ) work?


von Mike P (Guest)


Attached files:

Rate this post
useful
not useful
i'm new to GCC/Gnude and have been through a lot of makefile trouble 
which is finally solved but it appears i still have one remaining 
problem.

sprintf( ) doesn't work.  strcpy & strcat work fine.  i suspect there's 
a library initialization that isn't being called for some reason.  the 
code worked fine when i used the keil compiler.
sprintf(s, "Day %d", 1)

i have looked for the source for sprintf but have never found it. 
truthfully, i'm also not sure i'm looking in the right place.

I imagine i should be looking at http://www.gnu.org .  i found some 
source but never managed to find what i'm looking for.

thank you!
mp

von Martin T. (mthomas) (Moderator)


Rate this post
useful
not useful
Mike P wrote:
>sprintf( ) doesn't work.  strcpy & strcat work fine.  i suspect there's
>a library initialization that isn't being called for some reason.

Is there enough stack-space available? Is the heap initilalized? Does 
the linker set the "end"-symbol correctly?

>the code worked fine when i used the keil compiler.
>sprintf(s, "Day %d", 1)

I expect you do not use the "Keil compiler" (very outdated) but the 
Realview toolchain which comes with MDK-ARM but this will not help 
anyway. The interfaces for stdio functions like sprintf are standardized 
but the implementions are different.

> i have looked for the source for sprintf but have never found it.
> truthfully, i'm also not sure i'm looking in the right place.

stio-functions like sprintf are part of the libc. Most binary 
disitributions for the GNU ARM-cross-toolchain use the newlib as libc. 
If you are using such a package you will find the sources in the newlib 
CVS: 
http://sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/stdio/?cvsroot=src

>I imagine i should be looking at http://www.gnu.org .  i found some
>source but never managed to find what i'm looking for.

As far as I know the compiler can replace calls to sprintf which only 
use constant parameters which something like memcopy if optimization is 
enabled. Maybe you have found code for this in the gcc-sources but it 
will not help with non-constant parameters.

von Mike P (Guest)


Attached files:

Rate this post
useful
not useful
sorry for my slow reply--i've been taking what you've said & tried to 
learn some parts that could possibly help me.

>Is there enough stack-space available? Is the heap initilalized? Does
the linker set the "end"-symbol correctly?

sorry, i don't know how.  i'm just using an example.

>I expect you do not use the "Keil compiler" (very outdated)

yes; price

thank you for the source link.  sure is adorned with macros.  didn't see 
how to init that library.

in a way, that's probably not my biggest problem because i can't even 
make much in the way of calls.  sounds like stack trouble but i don't 
know how to fix that.  attached a file for that.

i expect i need to make the linker command line agree with simple.cmd 
and makefile and startup.s.  i tried by it was entirely unsuccessful.

can you help me?  i'm not accustomed to being so "stuck".  i'm a 
programmer by trade but haven't done much embedded stuff.  what i did do 
was arduino and some 8051 assembler.  they were so easy.  Arm is not.

thank you for any help you can provide!
mp

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.