MinGW: How do I temporarily disable stderr in a C(++) program

R

Richard

Harald van Dijk said:
On occasion Kenny'll provide useful answers, but his troll messages are best
ignored. That said, I disagree with your reply to him.

I have never seen him troll. Pointing out the retentive behaviour of
some of the regulars is a valuable input - it lets the nOOb know that
not everyone here is trying to win the "I bullied a nOOb"
competition. It is astonishing and frustrating to see the usual suspects
piling up on the same thread with the same "Its OT" comments. I don't
believe they are not aware that someone got there first. It's tedious
and somewhat pathetic. This behaviour exists in no other group to such
an extent.
 
V

Vince C.

Keith said:
It should be basically as simple as initializing device stderr when the
program starts, shouldn't it? There is code within stdlib that creates an
__iob[2] array of FILE*, each being stdout, stdin and stderr,
respectively. If my programm succeeds in doing the same, i.e.
re-initializing stderr with the default values, the trick is done. So I
asked the question if it was possible.

The C standard says nothing about __iob, or about stdin, stdout, and
stderr being elements of an array.

Googling the Internet about "stdio.c" listed some results which showed such
an implementation.

How do you know that iostream uses std* file descriptors? The C
standard certainly doesn't guarantee this.

That's how iostream are written. Function ios_base::sync_with_stdio() allows
for synchronizing iostream streams with standard C streams. They are
synchronized by default.
 
R

Richard Heathfield

Richard said:
I have never seen him troll.

Then presumably either you've killfiled him, or you keep your eyes
tightly closed when reading comp.lang.c, or you don't know what
trolling is, or you yourself are a troll.
Pointing out the retentive behaviour of
some of the regulars is a valuable input

No, it isn't. It's a complete waste of time. If P is the magnitude of a
particular poster's positive contributions to the group, and N is the
magnitude of their negative contributions, then they are valuable to
the group if N < P; the greater the difference, the greater the value.
And here's the weird thing - people are perfectly capable of deciding
for themselves whether they consider N < P for any given poster.

From what I've seen of Mr McCormack's articles, his N is huge, and his P
is just about 0. From what I've seen of your articles, your N is pretty
vast, albeit not as big as Mr McCormack's N, and your P is fairly
miniscule, although not as microscopic as Mr McCormack's. So I don't
ascribe any great value to your opinions about the group. If you worked
on your P a bit more, maybe I'd treat your N a bit more seriously. If
you really cared about the people whose interests you claim to be
protecting, you'd provide some high quality answers to their questions.
Instead, you do little but snap, snipe, and sneer.

Having said that, it is certainly true that some of the regular
contributors spend rather too much time berating those who are
incapable of learning. They would do better ignoring them completely.

Those who earnestly desire, and can profit from, high quality C advice
are perfectly capable of acting in a way that won't get them killfiled
by the C experts in this group. Those who can't act in a way that won't
get them killfiled are not going to be able to profit from the advice
they would have got, so no loss there. Let them content themselves with
broken answers from people who remain uncorrected only because nobody
with a clue is reading their articles any more.
 
V

Vince C.

Martin said:
Neither getopt() or getopt_long() is a standard C function. It might be
useful for you to review what functions are specific to your
implementation and which are standard C functions. This will have been
a useful exercise if you use what you learn to isolate those
non-standard functions into implementation-specific translation units.

Ok, these are not standards, sorry.
The day that you move out of Bill Gates's empire you will be glad that
you have taken these simple precaution. The day that the next version of
your implementation or of the next update to Windows might also be the
day that you are glad you have isolated those non-standard functions.

Rule number 1: never make assumptions about what the original poster said if
he/she didn't say it explicitly...

I never said *I* had installed W2K;
I never said I was working daily with Windows;
I never said that I liked it;
I never said Windows was my only platform;
I never said I wasn't aware about difference between M$ view of "standard"
and others

And I didn't say that, fed up of Window$, I switched to Gentoo Linux in
March 2004 and that I'm much more happy with it.

I've already moved way from Bill Gates' Empire...

Let me tell you a little about me.

In fact I've spent 10 years studying Windows and developing under Windows. I
started with C and soon C++. I was mainly developing GUI and system
applications while I never wrote console programs.

After I started being upset about losing control of my computer to the
profit of a monopolistic company, I started to look for something that
would allow me to get control aver my machine and to be able to decide what
I put onto it. I was advised Gentoo Linux.

That's the whole story of me.

This is just to warn I'm not a newbie and I hate being thrown at with abrupt
sentences like "You're off-topic". It's like I'd be to be shot at just
because I had pronounced the words "Windows". I said "it's like", I don't
mean it's the real reason.

Damn, I know that it's tempting to treat most Windows user like a computer
illiterate but it's only tempting. Noone's supposed to follow his/her
temptation without thinking a little. I recon there are many people asking
dummy questions and who deserve a blind "RTFM" but there is at least one
person who replied kindly, patiently to my question. I never do that to
anyone. Even with those I consider they are dummies for as dummies as they
are I consider there might always be something I can learn...

Not giving someone the slightest chance to explain is closing the door
before a conversation may occur. It's not my way of thinking.

Stating "Let me be the first to tell you ... [bla bla bla]" is all but a
demonstration of someone who wants to listen before bashing.

I just wonder why so little compassion and understanding. I didn't start my
post throwing bullets at anyone. If I was off topic, there sure was a kind
way to say it. And again, it doesn't prevent from responding in a gentle
way, seeking for the real matter, like another person has.

I have absolutely nothing against you, Martin. I just took the opportunity
of my response to go on a little further on that particular topic.
 
R

Richard

Richard Heathfield said:
Richard said:


Then presumably either you've killfiled him, or you keep your eyes
tightly closed when reading comp.lang.c, or you don't know what
trolling is, or you yourself are a troll.


No, it isn't. It's a complete waste of time. If P is the magnitude of
a

Not as much waste of time as reading your repetitive, glib "OT replies"
20 million times a day. You guys should split up the responsibility -
say you do all the names beginning with "n", Flash can have "a-d",
Santosh "e-g" etc.

*snip*
 
V

Vince C.

Flash said:
Those are not standard C functions. ....
Then ask on a GNU group, although I suspect you will find it depends on
the target platform not on whether you are running GNU code. Unless by
running GNU code you are limiting yourself to systems using the GNU
implementation of the standard C library, which I believe would actually
exclude MinGW and 3/4 of the systems on which I've used gcc. ....
If C++ is involved you need to ask else where, we don't deal with it here. ....
argtable2, getopt, get_opt and getopt_long are not standard.

Ok, these are not standard. But my question pointed at using stderr and only
that. Things like GNU, iostream, Windows and MinGW are the context. My
question didn't deal with them directly. (Although the real solution is to
use opterr but how could I have figured that out since I didn't realize I
had missed something?)

You can't in standard C.

Aaah, here we are :) . Thanks, I didn't know that.


....
Ah, so hassle for everyone else is OK but hassle for you is not?

That's not (that it's Ok for anyone else) what I meant, surely not.

Look, I had to make a choice: where should I post my question?

1. comp.lang.c++? Because I'm making C++ applications in general? or
2. something.gnu...? Because I'm using GNU tools? or
3. comp.lang.mingw (provided it existed)? Because I'm using MinGW? or
4. microsoft.public.windows2000...? Because I'm developing for Windows? or
5. comp.lang.c? Because I want to use standard C file descriptors in a way
for which I still need some information?

So should I write the whole story from the beginning, including the dozens
of lines that are irrelevant of the very first question? Or may I hope
someone pays attention to my question, asks the necessary questions to get
more information and, little by little, finally tells me the right
solution?

I've made a choice. And finally I've got answers. Maybe I was a little bit
lame selecting the right forum but I then expect someone to say it gently.
And I also expect good reasons for being off-topic.

Nothing against you personnally but I'm just justifying my choice, which I
shouldn't be supposed to do, IMHO.
 
M

Martin Ambuhl

Vince said:
Ok, these are not standards, sorry.


Rule number 1: never make assumptions about what the original poster said if
he/she didn't say it explicitly...

Rule number 1a: Never overlook the actual content of my posts just to
fuel your personal rants ...
I never said *I* had installed W2K;
I never said I was working daily with Windows;
I never said that I liked it;
I never said Windows was my only platform;
I never said I wasn't aware about difference between M$ view of "standard"
and others

Big deal. Everything I said applies *no matter what* implementation or
platform you are using. Go vent elsewhere.
 
R

Richard Heathfield

Richard said:
Not as much waste of time as reading your repetitive, glib "OT
replies" 20 million times a day.

Check your facts. I rarely bother to mention topicality to an OP who has
posted a question about something not topical in comp.lang.c. In fact,
I rarely bother to respond to such questions at all. When I do, it's
because I'm trying to give him or her the best advice on where to get a
high quality answer.

If you want to waste your time complaining about people posting
repetitive, glib complaints about topicality, then at least complain
about the people that actually do this.
 
R

Richard Heathfield

Vince C. said:
Flash Gordon wrote:


Ok, these are not standard. But my question pointed at using stderr
and only that.

That question was and is topical in comp.lang.c.
Things like GNU, iostream, Windows and MinGW are the
context. My question didn't deal with them directly.

It was reasonable to provide such context, although the iostream thing
does tend to hint that comp.lang.c++ might have been a better bet for
you.
(Although the
real solution is to use opterr but how could I have figured that out
since I didn't realize I had missed something?)

Well, quite so. Until you know what the answer is, it's sometimes
difficult to figure out where to ask the question.

I think the situation was somewhat complicated by the mention of
Windows, since Windows might reasonably be regarded as what the
Standard calls a "freestanding implementation"; as such, it is not
required to provide support for stdin, stdout, and stderr, and AFAIK it
doesn't.

Anyway, as far as I'm concerned the question was borderline topical
(perhaps even despite the C++ reference), even if the answer that
finally satisfied you ("use opterr") was not.

<snip>
 
K

Kenny McCormack

Not as much waste of time as reading your repetitive, glib "OT replies"
20 million times a day. You guys should split up the responsibility -
say you do all the names beginning with "n", Flash can have "a-d",
Santosh "e-g" etc.

Dicky Heathfield is a classic of specimen of "just doesn't get it" (and
never will).
 
D

Default User

Richard said:
Richard said:


Then presumably either you've killfiled him, or you keep your eyes
tightly closed when reading comp.lang.c, or you don't know what
trolling is, or you yourself are a troll.

The last choice is the correct one. I'm surprised there was any
question.



Brian
 
J

jacob navia

Richard Heathfield wrote:

[snip]
I think the situation was somewhat complicated by the mention of
Windows, since Windows might reasonably be regarded as what the
Standard calls a "freestanding implementation"; as such, it is not
required to provide support for stdin, stdout, and stderr, and AFAIK it
doesn't.

You are wrong. Windows provides support for stdin, stdout and stderr


The problem with mentioning windows in this newsgroup is that some
people will immediately think that you are a slave of the evil empire
and try to convince you of leaving your sinful ways and attain nirvana
with some linux version...
 
F

Flash Gordon

Vince C. wrote, On 15/07/07 00:47:
Flash Gordon wrote:


That's not (that it's Ok for anyone else) what I meant, surely not.

Look, I had to make a choice: where should I post my question?

1. comp.lang.c++? Because I'm making C++ applications in general? or

In general, yes, comp.lang.c++ is a better place to post when building a
C++ application, because C++ provides all sorts of facilities not
available in C including facilities for calling between C and C++. So
folks over in comp.lang.c++ will know what you can do in C++ and how
that will interract with what you can do in C.
2. something.gnu...? Because I'm using GNU tools? or

Actually, once you know that the functions giving you grief a GNU
specific ones (and not knowing that is an acceptable starting point),
yes, going to a GNU group is not a bad thing.
3. comp.lang.mingw (provided it existed)? Because I'm using MinGW? or

The are mingw groups and/or mailing lists I'm sure, so potentially yes.
Again, this applies once you know they are non-standard.
4. microsoft.public.windows2000...? Because I'm developing for Windows? or
5. comp.lang.c? Because I want to use standard C file descriptors in a way
for which I still need some information?

C does not have file descriptors ;-)

Seriously, C++ has the same standard file handles as C, so I would
expect asking about them in comp.lang.c++ would be acceptable, and C++
may be able to do things with them that C cannot.
So should I write the whole story from the beginning, including the dozens
of lines that are irrelevant of the very first question? Or may I hope
someone pays attention to my question, asks the necessary questions to get
more information and, little by little, finally tells me the right
solution?

A better way to ask your questions, and also much shorter, would have
been...

I'm using the getopt and getopt_long functions which are sending output
to stderr. I want to prevent these functions from sending error output
without stopping the rest of the application from writing to stderr.

See, much shorter and contains the important information. Note also that
the above states what you want to achieve, rather than simply saying how
you want to achieve it. By all means go on from there to say how you
were thinking of achieving your desired result, but ALWAYS start be
explaining the real problem you are trying to solve.
I've made a choice. And finally I've got answers. Maybe I was a little bit
lame selecting the right forum but I then expect someone to say it gently.
And I also expect good reasons for being off-topic.

You were given good reasons. You were just very lucky that someone
eventually found out what your real requirements were, rather than what
you initially asked about, and happened to know something about the
functions in question. Had you asked in a GNU group as soon as you were
told that getopt etc were non-standard you would probably have got an
answer much faster, thus benefiting you.
Nothing against you personnally but I'm just justifying my choice, which I
shouldn't be supposed to do, IMHO.

You don't have to justify it, just accept that it is wrong when it is
pointed out to you. You also need to develop a fairly thick skin, since
there are a lot of groups that are very tough, some of them from what I
here much tougher than here. There is also a lot of expertise.
 
F

Flash Gordon

jacob navia wrote, On 15/07/07 10:37:
Richard Heathfield wrote:

[snip]
I think the situation was somewhat complicated by the mention of
Windows, since Windows might reasonably be regarded as what the
Standard calls a "freestanding implementation"; as such, it is not
required to provide support for stdin, stdout, and stderr, and AFAIK
it doesn't.

You are wrong. Windows provides support for stdin, stdout and stderr

True in some situations, not in others. Some implementations on Windows
are freestanding, some are hosted, and with some (e.g. MSVC++, all
versions I've used) whether it is freestanding or hosted depends on how
you use it.
The problem with mentioning windows in this newsgroup is that some
people will immediately think that you are a slave of the evil empire
and try to convince you of leaving your sinful ways and attain nirvana
with some linux version...

Yes, that is a problem. However people also get told they are off topic
with GNU specific stuff, i.e. the GNU implementation of getopt as in
this case.
 
R

Richard

Default User said:
The last choice is the correct one. I'm surprised there was any
question.



Brian

As one of the worst offenders of loving the sound of your own voice in
the "OT" race, I expected nothing less from you. There appears to be
some kind of "mania" in this group. A shame as there are so many people
who know what they are talking about and could be so more helpful if
they were to drop the snide, picky sides which they use to advertise
their grudging availability between solving the worlds problems out
there in the real world.
 
K

Kenny McCormack

Flash Gordon said:
You were given good reasons. You were just very lucky that someone
eventually found out what your real requirements were, rather than what
you initially asked about, and happened to know something about the
functions in question. Had you asked in a GNU group as soon as you were
told that getopt etc were non-standard you would probably have got an
answer much faster, thus benefiting you.

Yup, just like that helpful genius Kenny McCormack initially observed.
 
K

Kenny McCormack

jacob navia wrote, On 15/07/07 10:37:
Richard Heathfield wrote:

[snip]
I think the situation was somewhat complicated by the mention of
Windows, since Windows might reasonably be regarded as what the
Standard calls a "freestanding implementation"; as such, it is not
required to provide support for stdin, stdout, and stderr, and AFAIK
it doesn't.

You are wrong. Windows provides support for stdin, stdout and stderr

True in some situations, not in others. Some implementations on Windows
are freestanding, some are hosted, and with some (e.g. MSVC++, all
versions I've used) whether it is freestanding or hosted depends on how
you use it.

It is pretty clear you don't know what you are talking about. You know
nothing about Windows, qua Windows and are just trying to use your CLC-ish
and Unix-y words, and appear to know something about a platform that you
despise.
Yes, that is a problem. However people also get told they are off topic
with GNU specific stuff, i.e. the GNU implementation of getopt as in
this case.

Yeah, but not with anywhere near the religious ferver that the 'W' word
inspires among you and the other faithful here.
 
R

Richard Heathfield

jacob navia said:
Richard Heathfield wrote:

[snip]
I think the situation was somewhat complicated by the mention of
Windows, since Windows might reasonably be regarded as what the
Standard calls a "freestanding implementation"; as such, it is not
required to provide support for stdin, stdout, and stderr, and AFAIK
it doesn't.

You are wrong. Windows provides support for stdin, stdout and stderr

Well, I didn't say it very well, did I? I apologise for expressing
myself poorly. Yes, if you're writing a console program, you can have
your stdin, stdout, and stderr. But I was in fact thinking specifically
of Win32 API programs, programs that actually use the Windowiness of
Windows. Now, it's entirely possible that Windows programs (of the
WinMain variety, so to speak) can take advantage of stdin/stdout/stderr
support, but I was under the impression that they cannot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top