public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Non-constant initializers
@ 1998-04-21 17:38 Ross Alexander
  1998-04-21 23:21 ` Per Bothner
  1998-04-22  3:17 ` Andreas Schwab
  0 siblings, 2 replies; 6+ messages in thread
From: Ross Alexander @ 1998-04-21 17:38 UTC (permalink / raw)
  To: egcs

It seems that code like

#include <stdio.h>

FILE *f = stdin;

int main()
{
..
}

fail because of non-constant initializer.  This did not happen before.
Is there any way to tell egcs-980321 how to handle this, or should I
upgrade.

-- 
Ross Alexander                       r.alexander@auckland.ac.nz
Department of Statistics
University of Auckland
New Zealand

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-constant initializers
  1998-04-21 17:38 Non-constant initializers Ross Alexander
@ 1998-04-21 23:21 ` Per Bothner
  1998-04-22  3:17 ` Andreas Schwab
  1 sibling, 0 replies; 6+ messages in thread
From: Per Bothner @ 1998-04-21 23:21 UTC (permalink / raw)
  To: Ross Alexander; +Cc: egcs

> It seems that code like
> FILE *f = stdin;
> fail because of non-constant initializer.  This did not happen before.

Er, whether this works depends on whether the language or C or C++
(whcih you did not specify) and what the definition of stdin is in
your C libraries (which you also did not specify).

It is supposed to work in C++, and it is undefined whether it works
in C:  It depends on the definition of stdin.  Under traditional
Unix it works, because stdin is &_iob[0]; under many other systems
it doesn't.  This is not a bug in egcs or libc, but a bug in your code.

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-constant initializers
  1998-04-21 17:38 Non-constant initializers Ross Alexander
  1998-04-21 23:21 ` Per Bothner
@ 1998-04-22  3:17 ` Andreas Schwab
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 1998-04-22  3:17 UTC (permalink / raw)
  To: Ross Alexander; +Cc: egcs

Ross Alexander <r.alexander@auckland.ac.nz> writes:

|> It seems that code like
|> #include <stdio.h>

|> FILE *f = stdin;

|> int main()
|> {
|> ..
|> }

|> fail because of non-constant initializer.  This did not happen before.
|> Is there any way to tell egcs-980321 how to handle this, or should I
|> upgrade.

You should not write that.  ISO C does not require std{in,out,err} to be a
constant expression.  This has nothing to do with the compiler, it's a
library issue.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
schwab@gnu.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-constant initializers
@ 1998-04-22 15:21 Mike Stump
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 1998-04-22 15:21 UTC (permalink / raw)
  To: r.alexander; +Cc: egcs

> To: Ross Alexander <r.alexander@auckland.ac.nz>
> From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
> Date: 22 Apr 1998 10:48:16 +0200

> Ross Alexander <r.alexander@auckland.ac.nz> writes:

> |> FILE *f = stdin;

> You should not write that.  ISO C does not require std{in,out,err}
> to be a constant expression.

Or, you can switch to C++.  It always allows that.  :-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Non-constant initializers
@ 1998-04-22  8:38 Kaz Kylheku
  0 siblings, 0 replies; 6+ messages in thread
From: Kaz Kylheku @ 1998-04-22  8:38 UTC (permalink / raw)
  To: 'Ross Alexander', egcs

On Tuesday, April 21, 1998 5:14 PM, Ross Alexander 
[SMTP:r.alexander@auckland.ac.nz] wrote:
> It seems that code like
>
> #include <stdio.h>
>
> FILE *f = stdin;
>
> int main()
> {
> ..
> }
>
> fail because of non-constant initializer.  This did not happen before.
> Is there any way to tell egcs-980321 how to handle this, or should I
> upgrade.

You need to upgrade your program to valid C. Nowhere in the standard
is it required that ``stdin'' be a constant expression; hence your
program is ill formed.

For example, stdin could quite naturally be be a static object
declared as

	extern FILE *stdin;

after which stdin is anything but a constant expression.

C programs which depend on stdin or stdout to expand to
address constants are simply not portable.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-constant initializers
       [not found] <199804220636.XAA08145@cygnus.com>
@ 1998-04-22  3:17 ` Ross Alexander
  0 siblings, 0 replies; 6+ messages in thread
From: Ross Alexander @ 1998-04-22  3:17 UTC (permalink / raw)
  To: Per Bothner; +Cc: egcs

> 
> > extern int *x;
> > int *y = x;
> 
> You say this works with C++, and doesn't work with C.
> Isn't that what I just said was how it was supposed to be?
> 
> > I can try and hunt down the problem but a few hints would come in handy.
> 
> There is no problem to track down.  Fix your code.

Sorry, I follow.  Unfortunately the behaviour

	FILE *blah = stdin;

is rather wide spread.  Normally this wouldn't matter that much but
both gnome and netscape are affected :-(.

I'll send them bug reports on the matter.

Again, many thanks for your time.
 
> 	--Per Bothner
> Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner
> 


-- 
Ross Alexander                       r.alexander@auckland.ac.nz
Department of Statistics
University of Auckland
New Zealand

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-04-22 15:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-21 17:38 Non-constant initializers Ross Alexander
1998-04-21 23:21 ` Per Bothner
1998-04-22  3:17 ` Andreas Schwab
     [not found] <199804220636.XAA08145@cygnus.com>
1998-04-22  3:17 ` Ross Alexander
1998-04-22  8:38 Kaz Kylheku
1998-04-22 15:21 Mike Stump

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 read-only IMAP folder(s) and NNTP newsgroup(s).