C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Potentially evaluated expression.

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
L.Suresh
Guest





PostPosted: Thu Jan 13, 2005 5:12 pm    Post subject: Potentially evaluated expression. Reply with 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?

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





PostPosted: Thu Jan 13, 2005 9:49 pm    Post subject: Re: Potentially evaluated expression. Reply with quote



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





PostPosted: Mon Jan 17, 2005 8:01 pm    Post subject: Re: Potentially evaluated expression. Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.