 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
L.Suresh Guest
|
Posted: Thu Jan 13, 2005 5:12 pm Post subject: Potentially evaluated expression. |
|
|
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! ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Thu Jan 13, 2005 9:49 pm Post subject: Re: Potentially evaluated expression. |
|
|
L.Suresh wrote:
| Quote: | 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.
| Quote: | 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.
| Quote: | 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
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Sebastian Redl Guest
|
Posted: Mon Jan 17, 2005 8:01 pm Post subject: Re: Potentially evaluated expression. |
|
|
L.Suresh wrote:
| Quote: | 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
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|