program doesn't "seem" to print "hello-out" | | |
The following program doesn't "seem" to print "hello-out". (Try
executing it)
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
What could be the reason? | | | | re: program doesn't "seem" to print "hello-out"
saurabhnsit2001 wrote: Quote:
The following program doesn't "seem" to print "hello-out". (Try
executing it)
>
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
>
>
What could be the reason?
>
if you add a line
fflush(stdout);
in the while loop , you will find out what really happenen. | | | | re: program doesn't "seem" to print "hello-out"
output to stderr goes out ASAP, output to stdout is often buffered up.
If you wait long enough you'll see the output appear. | | | | re: program doesn't "seem" to print "hello-out"
saurabhnsit2001 wrote: Quote:
>
The following program doesn't "seem" to print "hello-out". (Try
executing it)
>
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
>
What could be the reason?
Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep
function, in standard C (which is the subject of discussion here).
If you eliminate those things, resulting in:
#include <stdio.h>
int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}
there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout). stderr
is unbuffered, so it's output will probably appear. Terminate the
strings with '\n'.
--
Some informative links:
news:news.announce.newusers http://www.geocities.com/nnqweb/ http://www.catb.org/~esr/faqs/smart-questions.html http://www.caliburn.nl/topposting.html http://www.netmeister.org/news/learn2quote.html | | | | re: program doesn't "seem" to print "hello-out"
In article <44EEFD9C.EBA2FF7C@yahoo.com>,
CBFalconer <cbfalconer@maineline.netwrote:
.... Quote:
>Probably the fact that it shouldn't even compile on a standard C
>compiler. There is no such thing as <unistd.h>, nor a sleep
Now, that's just bogus. I suppose it could be said to be pedantically
correct if you replace "shouldn't" with "needn't". Pedantically
correct, but useless, of course, like most of the dreck posted to this ng. | | | | re: program doesn't "seem" to print "hello-out"
Kenny McCormack is a troll; do not respond to him/her. He/she only posts here
as a form of pathetic self-affirmation.
The only way to deal with trolls is to limit your reaction to reminding
others not to respond to trolls.
Information on trolls: http://members.aol.com/intwg/trolls.htm
--
Frederick Gotham | | | | re: program doesn't "seem" to print "hello-out"
Frederick Gotham wrote: Quote:
Kenny McCormack is a troll; do not respond to him/her. He/she only posts here
as a form of pathetic self-affirmation.
>
The only way to deal with trolls is to limit your reaction to reminding
others not to respond to trolls.
>
This _is_ bending the rules a bit, isn't it?
I prefer the "high-jack the thread for your own off-topic nonsense"
tactic, myself.
Hmmm. I have no off-topic nonsense to add. Unless this is it.
Yup. That's all I got. | | | | re: program doesn't "seem" to print "hello-out"
CBFalconer wrote: Quote:
#include <stdio.h>
>
int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}
>
there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout).
Well, that's an interesting answer. If it were true, that would
require every implementation of fprintf to by default allocate an
infinitely large output buffer, and every computer out there to have
infinite memory.
Or have an intelligent fprintf that could recognize repeated patterns
in what's passed to it and compress the output buffer on the fly.
Just 128 bits of repeat count would be enough for most purposes.
Hey! That's (to me) a new, and somewhat useful idea!. Think of all
the logging code that prints out humdrum, mostly repeated strings!
Out of the mouths of .......
stderr | | | | re: program doesn't "seem" to print "hello-out"
"Ancient_Hacker" <grg2@comcast.netwrites: Quote:
CBFalconer wrote:
> Quote:
>#include <stdio.h>
>>
>int main(void)
>{
> while(1) {
> fprintf(stdout, "hello-out");
> fprintf(stderr, "hello-err");
> }
> return 0;
>}
>>
>there is never any reason for any output to appear, due to the lack
>of any '\n' in the output nor any calls to fflush(stdout).
>
Well, that's an interesting answer. If it were true, that would
require every implementation of fprintf to by default allocate an
infinitely large output buffer, and every computer out there to have
infinite memory.
No, it just allows such an implementation. It doesn't require
it. Furthermore, an implementation is not required to support
text files with lines longer than 254 characters, including the
terminating new-line character.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman | | | | re: program doesn't "seem" to print "hello-out"
Kenny McCormack wrote: Quote:
In article <44EEFD9C.EBA2FF7C@yahoo.com>,
CBFalconer <cbfalconer@maineline.netwrote:
... Quote:
>>Probably the fact that it shouldn't even compile on a standard C
>>compiler. There is no such thing as <unistd.h>, nor a sleep
>
Now, that's just bogus. I suppose it could be said to be pedantically
correct if you replace "shouldn't" with "needn't". Pedantically
correct, but useless, of course, like most of the dreck posted to this ng.
Frederick Gotham wrote: Quote:
Kenny McCormack is a troll; do not respond to him/her. He/she only
posts here as a form of pathetic self-affirmation.
I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files and can link
to library routines, it just doesn't define them, so "needn't" is more
precise. Although the original post didn't define what these
non-ISO-9899 standard header and routine do, you could make an
intelligent guess. ;-)
This newsgroup revels in pedantry, so Kenny's non-abusive and, IMO,
accurate post certainly fits in.
--
Thad | | | | re: program doesn't "seem" to print "hello-out"
On Sat, 26 Aug 2006 17:04:42 -0600, in comp.lang.c , Thad Smith
<ThadSmith@acm.orgwrote: Quote:
>I don't know about Kenny's other posts, but his point above is
>legitimate. Standard C accepts non-standard header files and can link
>to library routines, it just doesn't define them, so "needn't" is more
>precise.
Strictly speaking the original quote was correct, and Kenny was wrong.
The header was nonstandard.
The header wasn't included in the post.
So the compiler cannot find it, and must issue a diagnostic and stop. Quote:
>This newsgroup revels in pedantry, so Kenny's non-abusive and, IMO,
>accurate post certainly fits in.
Although it was wrong... :-)
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan | | | | re: program doesn't "seem" to print "hello-out"
Mark McIntyre wrote: Quote:
On Sat, 26 Aug 2006 17:04:42 -0600, in comp.lang.c , Thad Smith
<ThadSmith@acm.orgwrote:
> Quote:
I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files and can link
to library routines, it just doesn't define them, so "needn't" is more
precise.
>
Strictly speaking the original quote was correct, and Kenny was wrong.
Strictly speaking the original quote was wrong, and Kenny was correct. Quote:
The header was nonstandard.
Yes. Quote:
The header wasn't included in the post.
Yes. Quote:
So the compiler cannot find it,
No. An implementation is permitted to provide it, and if it does, the
compiler /can/ find it. Quote:
and must issue a diagnostic and stop.
| | | | re: program doesn't "seem" to print "hello-out"
"CBFalconer" <cbfalconer@yahoo.com??????:44EEFD9C.EBA2FF7C@yaho o.com... Quote:
saurabhnsit2001 wrote: Quote:
>>
>The following program doesn't "seem" to print "hello-out". (Try
>executing it)
>>
> #include <stdio.h>
> #include <unistd.h>
>int main()
>{
>while(1)
>{
> fprintf(stdout,"hello-out");
> fprintf(stderr,"hello-err");
> sleep(1);
>}
> return 0;
>}
>>
>What could be the reason?
>
Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep
function, in standard C (which is the subject of discussion here).
If you eliminate those things, resulting in:
>
#include <stdio.h>
>
int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}
>
there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout). stderr
is unbuffered, so it's output will probably appear. Terminate the
strings with '\n'.
No, the output is appeared. After running the code without "sleep" function,
I got a full screen of interlaced "hello-out" and "hello-err". | | | | re: program doesn't "seem" to print "hello-out"
[snips]
On Sat, 26 Aug 2006 04:41:39 -0700, Ancient_Hacker wrote: Quote: Quote:
>there is never any reason for any output to appear, due to the lack of
>any '\n' in the output nor any calls to fflush(stdout).
>
Well, that's an interesting answer. If it were true, that would require
every implementation of fprintf to by default allocate an infinitely large
output buffer, and every computer out there to have infinite memory.
You neglect many options. Not least of which is a system that monitors
output and blocks apparent runaway applications from flooding the system
with pointless crud. | | | | re: program doesn't "seem" to print "hello-out"
Kelsey Bjarnason wrote: Quote:
[snips]
>
On Sat, 26 Aug 2006 04:41:39 -0700, Ancient_Hacker wrote:
> Quote: Quote:
there is never any reason for any output to appear, due to the lack of
any '\n' in the output nor any calls to fflush(stdout).
Well, that's an interesting answer. If it were true, that would require
every implementation of fprintf to by default allocate an infinitely large
output buffer, and every computer out there to have infinite memory.
>
You neglect many options. Not least of which is a system that monitors
output and blocks apparent runaway applications from flooding the system
with pointless crud.
That would be a good thing. But one suspects that it's a hard AI
problem to tell with any degree of certainty whether a program is
printing crud. Plenty of programs might have good reasons to
occasionally write out large amounts of repeating stuff. | | | | re: program doesn't "seem" to print "hello-out"
On 26 Aug 2006 15:58:58 -0700, in comp.lang.c , "Harald van D?k"
<truedfx@gmail.comwrote: Quote:
> Quote:
>The header was nonstandard.
>
>Yes.
> Quote:
>The header wasn't included in the post.
>
>Yes.
> Quote:
>So the compiler cannot find it,
>
>No. An implementation is permitted to provide it, and if it does, the
>compiler /can/ find it.
You're wrong but I really can't be bothered to explain why. Just think
"Standard" for a couple of minutes and see if it filters through.
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan | | | | re: program doesn't "seem" to print "hello-out"
Thad Smith <ThadSmith@acm.orgwrote: Quote:
Kenny McCormack wrote: Quote:
In article <44EEFD9C.EBA2FF7C@yahoo.com>,
CBFalconer <cbfalconer@maineline.netwrote:
... Quote:
>Probably the fact that it shouldn't even compile on a standard C
>compiler. There is no such thing as <unistd.h>, nor a sleep
Now, that's just bogus. I suppose it could be said to be pedantically
correct if you replace "shouldn't" with "needn't". Pedantically
correct, but useless, of course, like most of the dreck posted to this ng.
>
Frederick Gotham wrote: Quote:
Kenny McCormack is a troll; do not respond to him/her. He/she only
posts here as a form of pathetic self-affirmation.
>
I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files
Yes. However, ISO C doesn't guarantee that headers specified with <are
files at all. If it had been "unistd.h", he'd have had a point.
Richard |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|