EmbDev.net

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


Author: Mike P (Guest)
Posted on:
Attached files:

Rate this post
0 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

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 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/newli...

>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.

Author: Mike P (Guest)
Posted on:
Attached files:

Rate this post
0 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

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.