Re: (int)"text" as initializer



"Antoine Leca" <root@xxxxxxxxxxxxxxxxx> wrote in message news:4386e6ae$0$19915$626a54ce@xxxxxxxxxxxxxxx
> En news:1132907856.135044.202250@xxxxxxxxxxxxxxxxxxxxxxxxxxxx,
> the cancer va escriure:
> >
> > struct s {int a;} s = {(int)"test"};
> >
>
[...]
>
> My question is, is a compiler allowed to _reject_ it?
>

Yes, I think so. The interpretation you showed in your previous
posting seems to be correct to me. I doubt that the committee
(actually, the wording in question was written by Clive, as I recall
correctly) intentionally dropped that form, but in the current state
there is no way to say an implementation which rejects it is not
conforming.

And it is verly likely for the committee to reject a DR to request
addition of (int)"test" to the arithmetic constant expression, because
a s.c. program ('s output) can't depend on it anyway.

One interesting thing here is whether or not an implementation like
gcc 3.4 documents that "(int)"test"" constitutes an implementation-
defined form of the arithmetic constant expression. ;-)

[from your previous posting]
> const int t = (int)"text"; /* silently compiled */
>
> struct s {int a;} s = {(int)"text"}; /* rejected
> 'coz <<initializer must be constant>> */

I think this is also possible. Once it is subject to an implementation
-defined constant expression, an implementation is free to accept the
former rejecting the latter, as long as it documents it consistently.


--
Jun, Woong (woong at icu.ac.kr)
Information and Communications Univ.


.



Relevant Pages

  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... "If during the evaluation of an expression, ... a constant expression, in which case the program is illformed. ... enumeration types to arithmetic or enumeration types, ...
    (microsoft.public.vc.language)
  • Re: Reason for ISO ; warning
    ... "An arithmetic constant expression shall have arithmetic type and shall only have operands that are integer constants, floating constants, enumeration constants, character constants, and sizeof expressions. ... Cast operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic types, except as part of an operand to a sizeof operator whose ...
    (comp.lang.c)
  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... "An arithmetic constant expression shall satisfy the requirements for ... Thus 1.0f/0.0f is an "arithmetic constant expression". ... Undefined behaviour is just that, ... deduce about code correctness by looking how compilers behave. ...
    (microsoft.public.vc.language)

Loading