Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm From: hansm@cs.kun.nl (Hans Mulder) Newsgroups: comp.lang.c Subject: Re: Expressions in initializers Message-ID: <2842@wn1.sci.kun.nl> Date: 7 Mar 91 22:34:31 GMT References: <1991Mar4.144939.8311@ux1.cso.uiuc.edu> <1032@caslon.cs.arizona.edu> <3599.27d3ca8a@iccgcc.decnet.ab.com> Sender: root@sci.kun.nl Organization: University of Nijmegen, The Netherlands Lines: 30 In article <3599.27d3ca8a@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown) writes: >So a conforming compiler is free to consider sqrt(2.0) to be a >compile-time constant. Nope. The ANSI standard gives an exhaustive list of operators that can appear in a "constant expression" as required in an aggregate initialiser and function calls are not on the list. Consequently, struct silly { double d; } foo = { sqrt(2.0) }; is illegal. This has nothing to do with the question of whether the optimiser is allowed to replace foo.d = sqrt(2.0); by foo.d = 1.4142135623730950488; Also missing from the list is the array subscript operator, thus struct silly { char ch; } foo = { "hello"[3] }; is illegal, the fact that "hello"[3] == 'l' notwithstanding. Have a nice day, Hans Mulder hansm@cs.kun.nl