public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS]A question about printf
@ 2000-12-11  9:03 Andrea Acquaviva
  2000-12-11 13:30 ` Lewin A.R.W. Edwards
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Acquaviva @ 2000-12-11  9:03 UTC (permalink / raw)
  To: ecos-discuss

Hi,

I have a question about printf().
I noted that if I make two consecutive call to prinf or fprintf
functions
in my executables (also a simply modified hello world program), the
execution stops at the second function call, namely the second printf()
doesn't works at all.

What's the reason of this?

Thanks,
Andrea.


--
Ing. Andrea Acquaviva
D.E.I.S. - Universita' di Bologna
V.le Risorgimento, 2    40136 BOLOGNA (ITALY)
Tel: (+39) 051 20 93787 Fax: (+39) 051 2093786



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

* Re: [ECOS]A question about printf
  2000-12-11  9:03 [ECOS]A question about printf Andrea Acquaviva
@ 2000-12-11 13:30 ` Lewin A.R.W. Edwards
  2000-12-11 13:46   ` Jonathan Larmour
  0 siblings, 1 reply; 4+ messages in thread
From: Lewin A.R.W. Edwards @ 2000-12-11 13:30 UTC (permalink / raw)
  To: Andrea Acquaviva, ecos-discuss

Hello Andrea,

>I have a question about printf().
>I noted that if I make two consecutive call to prinf or fprintf
>functions in my executables (also a simply modified hello world program), the
>execution stops at the second function call, namely the second printf()
>doesn't works at all.

I was debugging some SmartMedia code today in eCos and noticed that the 
following code:

int i;
for (i=0;i<4096;i++) {
int k;
// some processing which assigns a value to k
printf("** Found logical block %d at physical block %d ",i, k);
}

would skip some of the last bytes of the output. However, if I added \n to 
the end of the printf format string, then all output is OK.

Looks like a buffering issue of some kind perhaps, try adding \n to the end 
of your printf strings and see if that fixes it.

=== Lewin A.R.W. Edwards (Embedded Engineer)
Work: http://www.digi-frame.com/
Personal: http://www.zws.com/ and http://www.larwe.com/

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

* Re: [ECOS]A question about printf
  2000-12-11 13:30 ` Lewin A.R.W. Edwards
@ 2000-12-11 13:46   ` Jonathan Larmour
  2000-12-11 13:55     ` Lewin A.R.W. Edwards
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Larmour @ 2000-12-11 13:46 UTC (permalink / raw)
  To: Lewin A.R.W. Edwards; +Cc: Andrea Acquaviva, ecos-discuss

"Lewin A.R.W. Edwards" wrote:
> 
> printf("** Found logical block %d at physical block %d ",i, k);
> }
> 
> would skip some of the last bytes of the output. However, if I added \n to
> the end of the printf format string, then all output is OK.
> 
> Looks like a buffering issue of some kind perhaps, try adding \n to the end
> of your printf strings and see if that fixes it.

This is completely correct for line-buffered output and is mandated by the
ISO C standard. There is no bug in this case.

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

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

* Re: [ECOS]A question about printf
  2000-12-11 13:46   ` Jonathan Larmour
@ 2000-12-11 13:55     ` Lewin A.R.W. Edwards
  0 siblings, 0 replies; 4+ messages in thread
From: Lewin A.R.W. Edwards @ 2000-12-11 13:55 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

Hi Jonathan,

> > printf("** Found logical block %d at physical block %d ",i, k);
> >
> > Looks like a buffering issue of some kind perhaps, try adding \n to the end
>
>This is completely correct for line-buffered output and is mandated by the
>ISO C standard. There is no bug in this case.

Well, please note that I didn't call it a bug, I called it an issue (or 
perhaps "behavior") and although I didn't realize it was part of ISO, I 
have dealt with the issue before and so it didn't bother me. In my case 
anyway it was only exposed by an outright bug in my code :)

=== Lewin A.R.W. Edwards (Embedded Engineer)
Work: http://www.digi-frame.com/
Personal: http://www.zws.com/ and http://www.larwe.com/

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

end of thread, other threads:[~2000-12-11 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-11  9:03 [ECOS]A question about printf Andrea Acquaviva
2000-12-11 13:30 ` Lewin A.R.W. Edwards
2000-12-11 13:46   ` Jonathan Larmour
2000-12-11 13:55     ` Lewin A.R.W. Edwards

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