Now everything is working fine... I followed your instructions,
recompile SDCC enabling floats. I also found your answer on
http://osdir.com/ml/compilers.sdcc.user/2007-02/msg00030.html to set
stack size, this made the "%d" in sprintf function work fine. Even
using a local buffer (buff) the result is fine. I tried this:
void main (void)
float fl1 = 18.725;
int INT = 18725;
char str = "bla";
char ch = 'C';
sprintf(buff,"KEY released. %.3f %d %c %s \r\n",fl1, INT, ch, str);
the output was: KEY released. 18.725 18725 C bla. Working well!
I'm an Electronic and Electrical Engineer (Telecommunications) and I like to develop
hardware projects and I believe that SDCC is a good option to develop C
firmware for Microchip's micro-controllers. I'll be working with SDCC,
trying hard to build my firmware and report any success or
failure with every SDCC function.
Thank you for your help. Best regards,
----- Mensagem Original----- De: Raphael Neider <email@example.com>
Reply-to: firstname.lastname@example.org Para:
email@example.com Assunto: Re: [Sdcc-user] sprintf
function and float and int (pic16) Data: Tue, 10 Feb 2009 23:52:16
> Please look in the manual under "Library Routines". It explains why
> floating point support is disabled in printf by default and how to turn
> it on.
Unfortunately this is not (yet) true for the pic16 targets to which you
were referring. Outputting float values was just not implemented in the
pic16-printf() routines, so recompiling would not have helped.
I just (svn r5371 and a fix in r5373) added support for float output to
pic16-printf(), but disabled it by default as with most other targets to
keep code size down for the majority of users (not using floats). You can
enable it by adding --enable-floats to the ./configure-call in the
device/lib/pic16/ directory when building sdcc from source. The
sdccman.lyx file is also updated with instructions to enable float support
when building the libraries.
Please try tomorrow's snapshot or the current svn revision and report any
problems occurring in the process (it works for me both with and without
float support, but who knows...).
>> void main (void)
>> float fl1 = 18.725;
>> int INT = 18725;
>> char str = "bla";
>> char ch = 'C';
>> sprintf(buff,"KEY released. %f %d %c %s \r\n",fl1, INT, ch, str);
>> same result: KEY released. <NO FLOAT> ? C bla.
Wow, you were able to use sprintf from the pic16 library?!? I also just
committed some fixes to the way stringbuffers are handled: Prior to these,
the pointer passed into sprintf would be modified by the
strmputchar()-routine to always point to the terminating 0 byte... Maybe
using a global buffer instead of a local pointer saved your day so far...
Again, any feedback on success or failure with sprintf/fprintf/... is
highly appreciated, especially before the upcoming release!
Thanks for reporting your problems.
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
Sdcc-user mailing list