* compile-error: stdin is not a constant
@ 1999-11-03 12:25 Wolfgang Haeuptli
1999-11-03 15:36 ` Daniel Jacobowitz
0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Haeuptli @ 1999-11-03 12:25 UTC (permalink / raw)
To: linuxppc-dev
Hello people
sorry for the (probably) basic question...
Since I installed R5, some programs (that used to compile OK on R4)
complain about :
initializer element for 'foo' is not constant
while compiling constructs like:
FILE *foo = stdin; (or FILE *foo = {(FILE *) stdin}; )
when I replaced this line with: FILE *foo = STDIN_FILENO;
( defined in unistd.h), compilation works, but the resulting program
segfaults...
Any hints to make this work would be very much appreciated.
Wolfgang Haeuptli
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: compile-error: stdin is not a constant
1999-11-03 12:25 compile-error: stdin is not a constant Wolfgang Haeuptli
@ 1999-11-03 15:36 ` Daniel Jacobowitz
1999-11-03 17:53 ` Martin Costabel
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 1999-11-03 15:36 UTC (permalink / raw)
To: linuxppc-dev
On Wed, Nov 03, 1999 at 01:25:44PM +0100, Wolfgang Haeuptli wrote:
>
> Hello people
>
> sorry for the (probably) basic question...
>
> Since I installed R5, some programs (that used to compile OK on R4)
> complain about :
>
> initializer element for 'foo' is not constant
>
> while compiling constructs like:
>
> FILE *foo = stdin; (or FILE *foo = {(FILE *) stdin}; )
Because it isn't a constant any more.
>
> when I replaced this line with: FILE *foo = STDIN_FILENO;
> ( defined in unistd.h), compilation works, but the resulting program
> segfaults...
Which should generate one hell of a warning, since STDIN_FILENO is a
small number, not a struct FILE *.
You need to initialize the variable early in main() or something along
those lines, or you can declare a constructor using __attribute__,
although I do not remember the syntax (search list archives).
Dan
/--------------------------------\ /--------------------------------\
| Daniel Jacobowitz |__| SCS Class of 2002 |
| Debian GNU/Linux Developer __ Carnegie Mellon University |
| dan@debian.org | | dmj+@andrew.cmu.edu |
\--------------------------------/ \--------------------------------/
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: compile-error: stdin is not a constant
1999-11-03 17:53 ` Martin Costabel
@ 1999-11-03 16:59 ` Daniel Jacobowitz
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 1999-11-03 16:59 UTC (permalink / raw)
To: linuxppc-dev
On Wed, Nov 03, 1999 at 05:53:59PM +0000, Martin Costabel wrote:
> Maybe this will work (1):
>
> FILE *foo = (FILE *) STDIN_FILENO;
No no no no no! STDIN_FILENO is a -number-, not a -pointer-!
> In a similar situation, I learned from Tom Rini that the correct way
> would be (2)
>
> static file *file ;
> static void file_construct (void) __attribute__((constructor));
> static void file_construct (void) { file = stdin; }
Yes, that's it. gcc specific, but works. (1) is DEFINITELY wrong.
Dan
/--------------------------------\ /--------------------------------\
| Daniel Jacobowitz |__| SCS Class of 2002 |
| Debian GNU/Linux Developer __ Carnegie Mellon University |
| dan@debian.org | | dmj+@andrew.cmu.edu |
\--------------------------------/ \--------------------------------/
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: compile-error: stdin is not a constant
1999-11-03 15:36 ` Daniel Jacobowitz
@ 1999-11-03 17:53 ` Martin Costabel
1999-11-03 16:59 ` Daniel Jacobowitz
0 siblings, 1 reply; 4+ messages in thread
From: Martin Costabel @ 1999-11-03 17:53 UTC (permalink / raw)
To: Daniel Jacobowitz, Wolfgang Haeuptli; +Cc: linuxppc-dev
Daniel Jacobowitz wrote:
>
> On Wed, Nov 03, 1999 at 01:25:44PM +0100, Wolfgang Haeuptli wrote:
> >
> > Hello people
> >
> > sorry for the (probably) basic question...
> >
> > Since I installed R5, some programs (that used to compile OK on R4)
> > complain about :
> >
> > initializer element for 'foo' is not constant
> >
> > while compiling constructs like:
> >
> > FILE *foo = stdin; (or FILE *foo = {(FILE *) stdin}; )
>
> Because it isn't a constant any more.
>
> >
> > when I replaced this line with: FILE *foo = STDIN_FILENO;
Maybe this will work (1):
FILE *foo = (FILE *) STDIN_FILENO;
> > ( defined in unistd.h), compilation works, but the resulting program
> > segfaults...
>
> Which should generate one hell of a warning, since STDIN_FILENO is a
> small number, not a struct FILE *.
>
> You need to initialize the variable early in main() or something along
> those lines, or you can declare a constructor using __attribute__,
> although I do not remember the syntax (search list archives).
In a similar situation, I learned from Tom Rini that the correct way
would be (2)
static file *file ;
static void file_construct (void) __attribute__((constructor));
static void file_construct (void) { file = stdin; }
This might be in the list archives somewhere. I had a similar problem
with stdout when compiling Scilab. I used Tom's version (2), and it
worked, but I saw that the Scilab people in a later version used the
shorter version (1), and this seems to work, too.
More precisely, they just added the "|| defined(__GNUC__)" in the
following code:
#if defined(__CYGWIN32__) || defined(__MINGW32__) || defined(__GNUC__)
static FILE *file= (FILE *) 0;
#define FPRINTF(x) ( file != (FILE*) 0) ? fprintf x : 0
#else
static FILE *file= stdout ;
#define FPRINTF(x) fprintf x
#endif
--
Martin
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1999-11-03 17:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-11-03 12:25 compile-error: stdin is not a constant Wolfgang Haeuptli
1999-11-03 15:36 ` Daniel Jacobowitz
1999-11-03 17:53 ` Martin Costabel
1999-11-03 16:59 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).