Assign file to stdout problem

J

Jason

I'm trying to port a C source code from Solaris to Linux and I have a
problem:
In a code line there is a declaration: >> static FILE *outfp=stdout; <<
and GCC gives the error: >> initializer element is not constant <<
How can I do that in another way to compile fine?
Thanks.
 
N

Nick

Jason said:
I'm trying to port a C source code from Solaris to Linux and I have a
problem:
In a code line there is a declaration: >> static FILE *outfp=stdout; <<
and GCC gives the error: >> initializer element is not constant <<
How can I do that in another way to compile fine?
Thanks.

It's not clear whether this is a file-scope static or a function one,
but in either case, probably the easiest way to do it is:

static FILE *outfp = NULL;

and (almost immediately if it's declared in a function, somewhere fairly
early in a suitable function (main perhaps?) if it's file-scope) do:

if (outfp == NULL)
outfp = stdout;

If you use NULL as a magic value that you don't want to get reset to
stdout, you need to make sure the flow is such that this only gets
executed once.
 
P

Peter Nilsson

Jason said:
I'm trying to port a C source code from Solaris to Linux
and I have a problem:
In a code line there is a declaration: >> static FILE
*outfp=stdout; <<
and GCC gives the error: >> initializer element is not
constant <<

That's because stdout is a macro and needn't be a compile
time constant.
How can I do that in another way to compile fine?

You could intialise outfp in a function block.

static FILE *outfp;

int main(void)
{
outfp = stdout;
return 0;
}

Although there's probably an even better solution, like
decoupling your functions from 'globals' and instead take
parameters.

void foo(FILE *outfp) { fputs("Hello World\n", outfp); }
 
S

Seebs


Posts listing the address as "(e-mail address removed)" from "aioe.org"
are presumptively trolls.

If you are not a troll, get a real Usenet provider and/or provide
a more plausible address.

-s
 
K

Keith Thompson

Seebs said:
Posts listing the address as "(e-mail address removed)" from "aioe.org"
are presumptively trolls.

I'll take your word for it that a lot of trolls use aioe.org,
but that hardly implies that all, or even most, aioe.org users
are trolls. I used to use aioe.org myself. And plenty of posters
use fake e-mail addresses to avoid spam. At least Jason uses an
address that doesn't match an actual domain.

I saw nothing trollish in the content of the article.

[...]
 
S

Seebs

I'll take your word for it that a lot of trolls use aioe.org,
but that hardly implies that all, or even most, aioe.org users
are trolls. I used to use aioe.org myself. And plenty of posters
use fake e-mail addresses to avoid spam.

Yes. But that *specific* address is very common in troll posts
to this group asking questions that are of the sort calculated to
get responses complaining about non-portable code.

There's been a bunch recently all with exactly that same address.

-s
 
L

luser- -droog

Yes.  But that *specific* address is very common in troll posts
to this group asking questions that are of the sort calculated to
get responses complaining about non-portable code.

There's been a bunch recently all with exactly that same address.

Besides which, this very issue was discussed not 2 months ago.
At the very least, one might reasonably recommend searching
before posting, and perhaps a skim through

www.catb.org/~esr/faqs/smart-questions.html
 
L

luser- -droog

The said:
<the latest in a series of succinct, code-ridden answers to silly questions>
<the latest in a series of silly questions modelled after real questions from preceding months>

Are you writing a new FAQ?
 
T

Tim Rentsch

Seebs said:
Posts listing the address as "(e-mail address removed)" from "aioe.org"
are presumptively trolls.

If you are not a troll, get a real Usenet provider and/or provide
a more plausible address.

The responded-to posting (which was snipped) did not deserve
this response. Get off your high horse.
 
S

Seebs

The responded-to posting (which was snipped) did not deserve
this response.

Yes it did. Whether or not the poster was a troll, his choice of an
invalid address, his choice of a Usenet provider, and his choice of question
happened to precisely match the pattern of a large number of recent spams.

If he wasn't a troll, he would benefit from knowing this. If he was,
there was no point in any other response.

Did he respond at any point to anything in the thread? I don't remember
him doing so, which would support my analysis. The troll using that pattern
generally didn't.
Get off your high horse.

Haven't got one.

-s
 
T

Tim Rentsch

Seebs said:
Yes it did. Whether or not the poster was a troll, his choice of an
invalid address, his choice of a Usenet provider, and his choice of question
happened to precisely match the pattern of a large number of recent spams.

The question was perfectly reasonable and a quite legitimate query.
It was not spam. As for the rest, unless the same question was
posted many times in a short period, they are irrelevant. That
didn't happen with this question.
If he wasn't a troll, he would benefit from knowing this. If he was,
there was no point in any other response.

If he is a troll, he doesn't care about your comments. If he
isn't a troll, they very well may drive him (and others) away
from the newsgroup. The downside far outweighs the upside.
Did he respond at any point to anything in the thread? [snip]

After your asshole response, why would he?
Haven't got one.

Your comments prove otherwise. If you want to play
moderator, take it out on comp.lang.c.moderated.
 
S

Seebs

The question was perfectly reasonable and a quite legitimate query.
It was not spam. As for the rest, unless the same question was
posted many times in a short period, they are irrelevant. That
didn't happen with this question.

*Substantively* identical includes, say, a dozen similar questions
posted by the same troll.
If he is a troll, he doesn't care about your comments. If he
isn't a troll, they very well may drive him (and others) away
from the newsgroup. The downside far outweighs the upside.

If he is a troll, being identified rather than getting nibbles
makes it less fun. If he isn't, it's useful to him to know why
people are ignoring him.
Did he respond at any point to anything in the thread? [snip]
After your asshole response, why would he?

I don't buy this "argument" at all. I was not being "an asshole".
I was telling him factually that his posts contained things which
would cause other participants to assume he was a troll. If he were
not a troll, this would be information of value to him. If he were,
he'd disappear until he could figure out a way to post without those
tells.
Your comments prove otherwise.

No, they don't.

And *plonk*. No amount of technical knowledge you have makes me feel
like putting up with you making up bullshit about my intent or internal
state.

-s
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top