Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Thanks. Paul. 8 5888
On Oct 20, 6:38Â*pm, "Paul Edwards" <kerra...@nosppaam.w3.towrote:
Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Thanks. Â*Paul.
In C99, you can do that. But I am not familar with C89, I can't promise
C89 also allows you to do that. I don't know why you are care for C89.
In fact, you can find the following rules in C99:
(1)
At program startup, three text streams are predeï¬ned and need not be
opened explicitly— standard input (for reading conventional input),
standard output (for writing conventional output), and standard error
(for writing diagnostic output).
(2)
If the main function returns to its original caller, or if the exit
function is called, all open ï¬les are closed (hence all output
streams are flushed) before program termination.
"Paul Edwards" <ke******@nosppaam.w3.towrote:
Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Yes, it's allowed. Whether it's wise is another matter, since in C89
there is no portable way to get it back, and in C99 there is one way
which is portable, but not guaranteed to work.
Richard
Richard Bos writes:
>Paul Edwards wrote:
>Is it permissible in C89 to do an "fclose(stdout)" and then exit, (...)
Yes, it's allowed. Whether it's wise is another matter, since in C89
there is no portable way to get it back,
Why would he want to get it back? He's exit()ing.
It's wise to close it if you want to exit with a failure if
fclose() failed, since exit() doesn't do that by itself.
--
Hallvard
Cong Wang wrote:
On Oct 20, 6:38 pm, "Paul Edwards" <kerra...@nosppaam.w3.towrote:
Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Thanks. Paul.
In C99, you can do that. But I am not familar with C89, I can't promise
C89 also allows you to do that. I don't know why you are care for C89.
In fact, you can find the following rules in C99:
(1)
At program startup, three text streams are predeï¬ned and need notbe
opened explicitly— standard input (for reading conventional input),
standard output (for writing conventional output), and standard error
(for writing diagnostic output).
But, at a bash prompt, I can type:
$ my_prog <&-
in which case the program starts up with stdin closed. Does this
mean that bash is a non-conforming environment?
--
Bill Pursell
"Richard Bos" <rl*@hoekstra-uitgeverij.nlwrote in message news:45****************@news.xs4all.nl...
"Paul Edwards" <ke******@nosppaam.w3.towrote:
Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Yes, it's allowed. Whether it's wise is another matter, since in C89
there is no portable way to get it back, and in C99 there is one way
which is portable, but not guaranteed to work.
Thankyou. Now is the application program allowed to
call fclose(stdout) twice, and if so, what is the expected
return on the second close?
BFN. Paul.
"Paul Edwards" <ke******@nosppaam.w3.towrites:
"Richard Bos" <rl*@hoekstra-uitgeverij.nlwrote in message
news:45****************@news.xs4all.nl...
>"Paul Edwards" <ke******@nosppaam.w3.towrote:
Is it permissible in C89 to do an "fclose(stdout)"
and then exit, or is the C runtime library allowed to
assume that stdout remains open and thus unconditionally
do an fclose itself?
Yes, it's allowed. Whether it's wise is another matter, since in C89 there is no portable way to get it back, and in C99 there is one way which is portable, but not guaranteed to work.
Thankyou. Now is the application program allowed to
call fclose(stdout) twice, and if so, what is the expected
return on the second close?
After a call to fclose(stdout), the value of stdout is indeterminate.
Calling fclose(stdout) a second time invokes undefined behavior.
If you call fclose(stdout) once, then it won't be closed again when
the program terminates. C99 7.20.4.3p4 says:
Next, all open streams with unwritten buffered data are flushed,
all open streams are closed, and all files created by the tmpfile
function are removed.
If stdout has been closed, then it isn't an open stream.
--
Keith Thompson (The_Other_Keith) ks***@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.
Paul Edwards wrote:
>
.... snip ...
>
Thankyou. Now is the application program allowed to
call fclose(stdout) twice, and if so, what is the expected
return on the second close?
Boom.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tsai Li Ming |
last post by:
Dear all,
I have a problem with a redirecting stdout and stderr. I am a top level
module and has no control over the imported modules that are making
system calls such as os.system or popen2.* ....
|
by: flupke |
last post by:
Hi,
I have a gui (made in wxPython) that enables a user to connect to a server
and issue some commands. The problem occurs when i try to disconnect the
client. It exits but it doesn't return to...
|
by: Leon |
last post by:
"stdout" is file object, it open mode is "w"
and it have a close() fuction.....
while it run close(), how to reopen it
because I want to do rewrite it
stdout content update
|
by: Mike |
last post by:
I would like my 'print' statements to send its output to the user's
screen and a log file.
This is my initial attempt:
class StdoutLog(file):
def __init__(self, stdout,...
|
by: Martijn Brouwer |
last post by:
I am writing a unix daemon in python, so I want to close stdin, stdout
and stderr.
My first attempt was to the standard file descriptors using their
close() methods. After closing stdout, I could...
|
by: Santtu Nyrhinen |
last post by:
Hi,
Let say that I have a function like
void writeHello() {
printf("Hello");
}
Now I need to make an automated test fot that function.
The test function returns 1 for successful and 0 for...
|
by: Vincent Delporte |
last post by:
Hi
I'm a Python newbie, and would like to rewrite this Perl scrip
to be run with the Asterisk PBX:
http://www.voip-info.org/wiki/view/Asterisk+NetCID
Anyone knows if those lines are...
|
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z |
last post by:
I wanna print the log to both the screen and file, so I simulatered a
'tee'
class Tee(file):
def __init__(self, name, mode):
file.__init__(self, name, mode)
self.stdout = sys.stdout...
|
by: Joakim Hove |
last post by:
Hello,
I have written a program in C; this programs uses an external
proprietary library. When calling a certain function in the external
library, the particular function writes a message to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |