Re: query about printf
- From: Antoninus Twink <nospam@xxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 12:52:07 +0000 (UTC)
On 28 May 2008 at 12:27, Rahul wrote:
I had a query reg printf(). I heard that it can't be used in ISR's as
it is non-re-enterant. I didn't get as to why printf is
non-re-enterant and why non-re-enterant library can't be used in an
ISR?
I believe POSIX requires the functions that write to streams to be
implemented in a re-entrant way (certainly this will be true if you're
using threads)... In general I don't think the famous ANSI C Standard
(praise be upon it!) insists on it. It's easy to imagine an
implementation of printf() that used a static internal buffer to build
up the string before sending it to stdout, for example.
If you call a non-reentrant function from an ISR, what if the code you
interrupted was another call to the same function? You'd likely corrupt
both the interrupted function's data and the data in the function called
by your ISR.
In any case, calling printf() in an ISR is almost certainly a mistake,
reentrant or not. Latency considerations mean that you really don't want
to be calling big bloated functions like printf() inside an ISR - you
would be blocking further interrupts for far too long.
.
- Follow-Ups:
- Re: query about printf
- From: Eric Sosman
- Re: query about printf
- References:
- query about printf
- From: Rahul
- query about printf
- Prev by Date: Re: [OT] Getting a random number
- Next by Date: Re: calling function in C
- Previous by thread: query about printf
- Next by thread: Re: query about printf
- Index(es):
Relevant Pages
|