"An expression is potentially evaluated unless it appears where an
integral constant expression is required (see 5.19)..."
Can someone give me an example of this.
Let's say i define
int y[20 * 5];
Is the expression 20 * 5 not evaluated then?
5.19/1 "In particular, except in sizeof expressions, functions, class
objects, pointers, or references shall not be used, and assignment,
increment, decrement, function-call, or comma operators shall not be
used"
Is the following code valid C++? It does not use a constant expression
in the first place and it also uses the decrement and comma operators.
int i = 8;
int x[--i];
int y[--i, i + 5];
Thanks for your time.
--lsu
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
I think "evaluation" refers to run-time. Here the constant expression
is used by the compiler to determine the array size. After that is done,
there is no more "expression" to talk about.
> 5.19/1 "In particular, except in sizeof expressions, functions, class
> objects, pointers, or references shall not be used, and assignment,
> increment, decrement, function-call, or comma operators shall not be
> used"
>
> Is the following code valid C++?
No.
> It does not use a constant expression
> in the first place and it also uses the decrement and comma operators.
>
> int i = 8;
> int x[--i];
> int y[--i, i + 5];
Victor
> 5.19/1 "In particular, except in sizeof expressions, functions, class
> objects, pointers, or references shall not be used, and assignment,
> increment, decrement, function-call, or comma operators shall not be
> used"
>
> Is the following code valid C++? It does not use a constant expression
> in the first place and it also uses the decrement and comma operators.
C++98 doesn't allow variables to specify stack array size. So the code is
invalid.
Were i a constant, the code would still be invalid because --i would be
attempting to modify it.
--
Sebastian Redl