Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Assign file to stdout problem

Reply
Thread Tools

Assign file to stdout problem

 
 
Jason
Guest
Posts: n/a
 
      12-04-2010
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.
 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      12-04-2010
Jason <(E-Mail Removed)> writes:

> 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.
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      12-04-2010
Jason <(E-Mail Removed)> wrote:
> 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); }

--
Peter
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-05-2010
On 2010-12-04, Jason <(E-Mail Removed)> wrote:
> I'm


Posts listing the address as "(E-Mail 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
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-05-2010
Seebs <(E-Mail Removed)> writes:
> On 2010-12-04, Jason <(E-Mail Removed)> wrote:
>> I'm

>
> Posts listing the address as "(E-Mail 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.

[...]

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-05-2010
On 2010-12-05, Keith Thompson <(E-Mail Removed)> wrote:
> 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
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
luser- -droog
Guest
Posts: n/a
 
      12-05-2010
On Dec 5, 2:44*am, Seebs <(E-Mail Removed)> wrote:
> On 2010-12-05, Keith Thompson <(E-Mail Removed)> wrote:
>
> > 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.
>


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


 
Reply With Quote
 
luser- -droog
Guest
Posts: n/a
 
      12-06-2010


The China Blue and the Gray wrote:
> <the latest in a series of succinct, code-ridden answers to silly questions>
> In article <idegnk$21o$(E-Mail Removed)>, Jason <(E-Mail Removed)>
> wrote:
> <the latest in a series of silly questions modelled after real questions from preceding months>
>


Are you writing a new FAQ?
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      01-02-2011
Seebs <(E-Mail Removed)> writes:

> On 2010-12-04, Jason <(E-Mail Removed)> wrote:
>> I'm

>
> Posts listing the address as "(E-Mail 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.
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      01-02-2011
On 2011-01-02, Tim Rentsch <(E-Mail Removed)> wrote:
> Seebs <(E-Mail Removed)> writes:
>> On 2010-12-04, Jason <(E-Mail Removed)> wrote:
>>> I'm


>> Posts listing the address as "(E-Mail Removed)" from "aioe.org"
>> are presumptively trolls.


> 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
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign file to stdout problem Edward Rutherford C Programming 1 10-16-2011 07:33 PM
sys.stdout assign to- bug castironpi@gmail.com Python 1 03-13-2008 07:10 AM
beginner Q: Kernel#puts, STDOUT, $stdout relation Andreas S Ruby 3 12-09-2006 12:39 AM
Problems redirecting STDOUT (NOT sys.stdout) to a pipe. Elad Python 0 03-19-2006 01:30 PM
copy stdout fails with permission denied when stdout is redirected brian.mabry.edwards@gmail.com Perl Misc 2 12-07-2005 10:49 PM



Advertisments