• Post Reply Bookmark Topic Watch Topic
  • New Topic

Definite Assignment and Expressions.Boolean Constant Expressions.  RSS feed

 
Sergej Smoljanov
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When local or fial variable is assigned i find this in jls but cant understand meaning.
• V is [un]assigned after any constant expression (§15.28) whose value is true
when false.
• V is [un]assigned after any constant expression whose value is false when true.
• V is [un]assigned after any constant expression whose value is true when true
iff V is [un]assigned before the constant expression.
• V is [un]assigned after any constant expression whose value is false when false
iff V is [un]assigned before the constant expression.
• V is [un]assigned after a boolean-valued constant expression e iff V is
[un]assigned after e when true and V is [un]assigned after e when false.

This is equivalent to saying that V is [un]assigned after e iff V is [un]assigned before e.
Because a constant expression whose value is true never has the value false, and a
constant expression whose value is false never has the value true, the first two rules are
vacuously satisfied. They are helpful in analyzing expressions involving the operators &&
(§16.1.2), || (§16.1.3), ! (§16.1.4), and ? : (§16.1.5).


aslo from jls

In order to precisely specify all the cases of definite assignment, the rules in this section define several technical terms:

whether a variable is definitely assigned before a statement or expression;
whether a variable is definitely unassigned before a statement or expression;
whether a variable is definitely assigned after a statement or expression; and
whether a variable is definitely unassigned after a statement or expression.

For boolean-valued expressions, the last two are refined into four cases:

whether a variable is definitely assigned after the expression when true;
whether a variable is definitely unassigned after the expression when true;
whether a variable is definitely assigned after the expression when false; and
whether a variable is definitely unassigned after the expression when false.


JLS7
what is code example of
• V is [un]assigned after any constant expression whose value is false when true.
• V is [un]assigned after any constant expression whose value is true when true
iff V is [un]assigned before the constant expression.
• V is [un]assigned after any constant expression whose value is false when false
iff V is [un]assigned before the constant expression.
• V is [un]assigned after a boolean-valued constant expression e iff V is
[un]assigned after e when true and V is [un]assigned after e when false.

? (because i cant understand)
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first two mean that V definitely has a value after a constant boolean expression, if the value of the expression is true, and the value of the expression is false. Since there are no expressions that can be both true and false at the same time, every one of these expressions satisfies the rule (since there are none). This also means there is no code example because it's simply impossible.

The next two state that it doesn't really matter what the value of the constant expression is, if V is assigned *before* the expression. Here's an example:
The last line states that V is assigned after the expression if V is assigned after the expression. This seems trivial, but here's an example:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!