Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Potentially evaluated expression.

1 view
Skip to first unread message

L.Suresh

unread,
Jan 13, 2005, 12:12:32 PM1/13/05
to
I'm having problems in understanding 3.2/1.

"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! ]

Victor Bazarov

unread,
Jan 13, 2005, 4:49:43 PM1/13/05
to
L.Suresh wrote:
> I'm having problems in understanding 3.2/1.
>
> "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?

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

Sebastian Redl

unread,
Jan 17, 2005, 3:01:44 PM1/17/05
to
L.Suresh wrote:

> 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

0 new messages