When "printf" function returns "EOF"? Will "printf" ever fail?
EOF from printf
Collapse
This topic is closed.
X
X
-
v4vijayakumarTags: None -
Keith Thompson
Re: EOF from printf
"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrites:C99 7.19.6.3p3:When "printf" function returns "EOF"? Will "printf" ever fail?
The printf function returns the number of characters transmitted,
or a negative value if an output or encoding error occurred.
The negative value isn't necessarily the same as EOF, and you
shouldn't assume that it is.
Any decent C textbook, or your system's documentation, should answer
this for you.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
-
v4vijayakumar
Re: EOF from printf
On Mar 27, 1:12 pm, Keith Thompson <k...@mib.orgwr ote:Thanks. I tried, "man 3 printf" in cygwin. It says,"v4vijayaku mar" <vijayakumar.su bbu...@gmail.co mwrites:>When "printf" function returns "EOF"? Will "printf" ever fail?
C99 7.19.6.3p3:
>
The printf function returns the number of characters transmitted,
or a negative value if an output or encoding error occurred.
>
The negative value isn't necessarily the same as EOF, and you
shouldn't assume that it is.
>
---
RETURNS
`sprintf' and `asprintf' return the number of bytes in
the output
string, save that the concluding `NULL' is not counted.
`printf' and
`fprintf' return the number of characters transmitted. If
an error
occurs, `printf' and `fprintf' return `EOF' and `asprintf'
returns -1.
No error returns occur for `sprintf'.
---
I just wanted to know, in which cases it can fail.
Why it returns negative value, when "EOF" would suffice? Does the
negative
return value has any more information for the failure?
Comment
-
Servé Laurijssen
Re: EOF from printf
"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote in message
news:1174979387 .734000.8370@r5 6g2000hsd.googl egroups.com...On some systems printf causes data to be printed on a serial line. printfWhen "printf" function returns "EOF"? Will "printf" ever fail?
doesnt need to print to a computer screen, on some systems it can be really
useful to test for the return value of printf
Comment
-
Malcolm McLean
Re: EOF from printf
"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote in messageNot printf() never fails. It is like my Volvo. It has never been for aWhen "printf" function returns "EOF"? Will "printf" ever fail?
>
repair in over five years.
Seriously, there are all sorts of things that could possibly go wrong with
printf(), such as the operating system running out of memory, or the
terminal crashing. But on a modern system they won't and the possibility can
be discounted.
If you are running on some sort of 4-bit digital watcvh with a teletype
attrached for debugging it might be a different story.
--
Free games and programming goodies.
Comment
-
=?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
Re: EOF from printf
Malcolm McLean wrote:On modern systems, printf can easily fail when output is not directed"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote in messageNot printf() never fails. It is like my Volvo. It has never been for aWhen "printf" function returns "EOF"? Will "printf" ever fail?
repair in over five years.
>
Seriously, there are all sorts of things that could possibly go wrong with
printf(), such as the operating system running out of memory, or the
terminal crashing. But on a modern system they won't and the possibility can
be discounted.
>
If you are running on some sort of 4-bit digital watcvh with a teletype
attrached for debugging it might be a different story.
to any sort of terminal. An easy example is running out of disk space.
Comment
-
CBFalconer
Re: EOF from printf
v4vijayakumar wrote:When "printf" returns EOF the function has already failed. From>
When "printf" function returns "EOF"? Will "printf" ever fail?
N869:
[#14] The fprintf function returns the number of characters
transmitted, or a negative value if an output or encoding
error occurred.
However, it may never return EOF.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
--
Posted via a free Usenet account from http://www.teranews.com
Comment
-
Flash Gordon
Re: EOF from printf
Malcolm McLean wrote, On 27/03/07 20:42:Or someone has redirected standard output to a file and the disk has"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote in messageNot printf() never fails. It is like my Volvo. It has never been for a>When "printf" function returns "EOF"? Will "printf" ever fail?
>>
repair in over five years.
>
Seriously, there are all sorts of things that could possibly go wrong
with printf(), such as the operating system running out of memory, or
the terminal crashing. But on a modern system they won't and the
possibility can be discounted.
>
If you are running on some sort of 4-bit digital watcvh with a teletype
attrached for debugging it might be a different story.
filed up (this does happen). Or standard output is redirected to a
TCP/IP port and the connection has disappeared (this does happen). Or
someone is running the program using a remote shell and the connection
has dropped (this does happen). I'm sure if I tried I could come up with
more examples where printf would fail, these are just a few REAL
examples where printf CAN fail on a MODERN system.
--
Flash Gordon
Comment
-
Mark L Pappin
Re: EOF from printf
CBFalconer <cbfalconer@yah oo.comwrites:
....v4vijayakumar wrote:>>When "printf" function returns "EOF"? Will "printf" ever fail?
When "printf" returns EOF the function has already failed.
To clarify for others: this final statement is almost certainlyHowever, it may never return EOF.
intended to mean
It is possible for printf() to never return EOF.
(There are many other negative values it could return, all of which
indicate occurrence of an error.)
(Chuck's final statement _could_ be read as
It is not possible for printf() to return EOF.
This reading would be incorrect, but the ambiguity of "may never VERB"
leads as validly to this as to the previous parsing.)
mlp
Comment
-
Richard Bos
Re: EOF from printf
"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote:
That gives you the Ganuck definition of printf(), which may includeOn Mar 27, 1:12 pm, Keith Thompson <k...@mib.orgwr ote:>"v4vijayaku mar" <vijayakumar.su bbu...@gmail.co mwrites:C99 7.19.6.3p3:When "printf" function returns "EOF"? Will "printf" ever fail?
The printf function returns the number of characters transmitted,
or a negative value if an output or encoding error occurred.
The negative value isn't necessarily the same as EOF, and you
shouldn't assume that it is.
Thanks. I tried, "man 3 printf" in cygwin.
more, or even fewer, restrictions than the ISO C one.
Any number of causes which can stop a program from reading a file. ForI just wanted to know, in which cases it can fail.
example, if the file was on a USB stick and you just pulled it out; or
if the disk has a read error; well, you name it, really.
Contrariwise, why demand that it return EOF (not "EOF"; printf() returnsWhy it returns negative value, when "EOF" would suffice?
an int, so it cannot possibly return "EOF", which is a string literal),
when allowing it to return any negative value works fine?
Richard
Comment
-
Richard Bos
Re: EOF from printf
rlb@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Erm. s/reading/writing/ and s/read/write/, obviously. The point being,"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote:
>>Thanks. I tried, "man 3 printf" in cygwin.
That gives you the Ganuck definition of printf(), which may include
more, or even fewer, restrictions than the ISO C one.
>>I just wanted to know, in which cases it can fail.
Any number of causes which can stop a program from reading a file. For
example, if the file was on a USB stick and you just pulled it out; or
if the disk has a read error; well, you name it, really.
that printf() prints to stdout, which may be a screen, but also may be
any other default output device, including (possibly the most often used
alternative) files. But never an input file... *Slaps self*
Richard
Comment
-
CBFalconer
Re: EOF from printf
Mark L Pappin wrote:Correct. I suspect this is an outgrowth of existing practice inCBFalconer <cbfalconer@yah oo.comwrites:...>v4vijayakuma r wrote:
>>>>>>When "printf" function returns "EOF"? Will "printf" ever fail?
>When "printf" returns EOF the function has already failed.
>>>However, it may never return EOF.
To clarify for others: this final statement is almost certainly
intended to mean
>
It is possible for printf() to never return EOF.
>
(There are many other negative values it could return, all of
which indicate occurrence of an error.)
the days of preparing C89. EOF satisfies the requirements of
printf, but there probably existed systems that did otherwise. So
you have to apply the < 0 test.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
--
Posted via a free Usenet account from http://www.teranews.com
Comment
-
Default User
Re: EOF from printf
Mark L Pappin wrote:
I think "it might never return EOF" would be less ambiguous.CBFalconer <cbfalconer@yah oo.comwrites:
>...v4vijayakumar wrote:When "printf" returns EOF the function has already failed.When "printf" function returns "EOF"? Will "printf" ever fail?
>>However, it may never return EOF.
To clarify for others: this final statement is almost certainly
intended to mean
>
It is possible for printf() to never return EOF.
>
(There are many other negative values it could return, all of which
indicate occurrence of an error.)
>
>
(Chuck's final statement could be read as
>
It is not possible for printf() to return EOF.
>
This reading would be incorrect, but the ambiguity of "may never VERB"
leads as validly to this as to the previous parsing.)
Brian
Comment
-
Keith Thompson
Re: EOF from printf
rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:[...]"v4vijayaku mar" <vijayakumar.su bburaj@gmail.co mwrote:A mostly off-topic quibble:>>Thanks. I tried, "man 3 printf" in cygwin.
That gives you the Ganuck definition of printf(), which may include
more, or even fewer, restrictions than the ISO C one.
I assume that "Ganuck" is meant to refer to gcc. In fact, there is no
gcc definition of printf. In Cygwin, the proided printf is part of
glibc, which is a separate package.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment
-
Keith Thompson
Re: EOF from printf
Keith Thompson <kst-u@mib.orgwrites :
[...]I meant "provided", of course.I assume that "Ganuck" is meant to refer to gcc. In fact, there is no
gcc definition of printf. In Cygwin, the proided printf is part of
glibc, which is a separate package.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment
Comment