public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] diag_printf and float problem
@ 2007-04-03 13:01 Tomasz Kutyla
  2007-04-03 13:15 ` Gary Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Tomasz Kutyla @ 2007-04-03 13:01 UTC (permalink / raw)
  To: ecos-discuss

Hi,

It seems to be some tiny problem but it happens;)

My code looks like below:

float f  = 10.5;
diag_printf("Test F = %f", f);

and on the terminal I've got:
Test F = %f

Why is that??

Regards,

Tomasz

-- 
Tomasz Kutyla, Design Engineer
MARP Electronic Sp. z o.o., ul. Pachonskiego 9, 31-223 Krakow
tel. +48 12 415-87-29 (ext. 35), mob.: +48 693 112 191
fax +48 12 415-86-80

e-mail: tkutyla@marp.pl; http://www.marp.pl


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] diag_printf and float problem
  2007-04-03 13:01 [ECOS] diag_printf and float problem Tomasz Kutyla
@ 2007-04-03 13:15 ` Gary Thomas
  2007-04-03 13:48   ` Tomasz Kutyla
  0 siblings, 1 reply; 4+ messages in thread
From: Gary Thomas @ 2007-04-03 13:15 UTC (permalink / raw)
  To: Tomasz Kutyla; +Cc: ecos-discuss

Tomasz Kutyla wrote:
> Hi,
> 
> It seems to be some tiny problem but it happens;)
> 
> My code looks like below:
> 
> float f  = 10.5;
> diag_printf("Test F = %f", f);
> 
> and on the terminal I've got:
> Test F = %f
> 
> Why is that??

diag_printf() doesn't support floating point.  If you need to print
floating point values, you'll need to use the stdio printf() function.

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] diag_printf and float problem
  2007-04-03 13:15 ` Gary Thomas
@ 2007-04-03 13:48   ` Tomasz Kutyla
  2007-04-03 13:56     ` Gary Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Tomasz Kutyla @ 2007-04-03 13:48 UTC (permalink / raw)
  To: Gary Thomas; +Cc: ecos-discuss


>>
>> It seems to be some tiny problem but it happens;)
>>
>> My code looks like below:
>>
>> float f  = 10.5;
>> diag_printf("Test F = %f", f);
>>
>> and on the terminal I've got:
>> Test F = %f
>>
>> Why is that??
>
> diag_printf() doesn't support floating point.  If you need to print
> floating point values, you'll need to use the stdio printf() function.
Thanks Gary, now it works;) Funny thing occurs: when I use printf like this:

diag_printf("test diag\n");
printf("##Test F = %.1f", f);

system waits for some printf functions to put the stream to the 
terminal. So I got:

test diag
test diag
test diag
test diag
##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 
10.5##Test F = 10.5##Test F = 10.5
test diag
test diag
test diag
test diag
test diag
##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 
10.5##Test F = 10.5##Test F = 10.5

But when I use printf like this:

diag_printf("test diag\n");
printf("##Test F = %.1f\n", f);

I got on the terminal:

test diag
##Test F = 10.5
test diag
##Test F = 10.5
test diag
##Test F = 10.5
test diag
##Test F = 10.5

I'm writing it because maybe it will help somebody in the future with 
the situation like mine;)

Best regards
Tomasz;)


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] diag_printf and float problem
  2007-04-03 13:48   ` Tomasz Kutyla
@ 2007-04-03 13:56     ` Gary Thomas
  0 siblings, 0 replies; 4+ messages in thread
From: Gary Thomas @ 2007-04-03 13:56 UTC (permalink / raw)
  To: Tomasz Kutyla; +Cc: ecos-discuss

Tomasz Kutyla wrote:
> 
>>>
>>> It seems to be some tiny problem but it happens;)
>>>
>>> My code looks like below:
>>>
>>> float f  = 10.5;
>>> diag_printf("Test F = %f", f);
>>>
>>> and on the terminal I've got:
>>> Test F = %f
>>>
>>> Why is that??
>>
>> diag_printf() doesn't support floating point.  If you need to print
>> floating point values, you'll need to use the stdio printf() function.
> Thanks Gary, now it works;) Funny thing occurs: when I use printf like 
> this:
> 
> diag_printf("test diag\n");
> printf("##Test F = %.1f", f);
> 
> system waits for some printf functions to put the stream to the 
> terminal. So I got:
> 
> test diag
> test diag
> test diag
> test diag
> ##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 
> 10.5##Test F = 10.5##Test F = 10.5
> test diag
> test diag
> test diag
> test diag
> test diag
> ##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 10.5##Test F = 
> 10.5##Test F = 10.5##Test F = 10.5
> 
> But when I use printf like this:
> 
> diag_printf("test diag\n");
> printf("##Test F = %.1f\n", f);
> 
> I got on the terminal:
> 
> test diag
> ##Test F = 10.5
> test diag
> ##Test F = 10.5
> test diag
> ##Test F = 10.5
> test diag
> ##Test F = 10.5
> 
> I'm writing it because maybe it will help somebody in the future with 
> the situation like mine;)

This is totally expected behaviour.  diag_printf() is not buffered, so whatever
you print comes out immediately.  printf() is buffered - nothing is actually
printed until the buffer gets full or you print a newline (\n).

Try running the same code on Linux - use fprintf(stderr, ...) where you have
diag_printf() and you'll see more or less the same behaviour.



-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-04-03 13:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-03 13:01 [ECOS] diag_printf and float problem Tomasz Kutyla
2007-04-03 13:15 ` Gary Thomas
2007-04-03 13:48   ` Tomasz Kutyla
2007-04-03 13:56     ` Gary Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).