Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

post - pre increment

 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt
JLS 15.14.1 says
the result of the postfix expression must be a variable of a numeric type, or a compile time error occurs.
JLS 15.15.1 says

the result of prefix increment expression is not a variable, but a value.

what exacly does it signify. I thought that it would be possible to do something like x++ = y ( because result of x++ is a variable) but it doesnt work like that.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the entire first paragraph of 15.14.1 and the entire first paragraph of 15.15.1, you find that they are nearly identical - the only difference is that the word "prefix" is replaced with "postfix". You are comparing two quotes from different positions in the paragraphs, without looking carefully at the exact wording. No need to look at two different sections to get those sentences - you can find nearly the same sentences you cited within the same paragraph at the beginning of 15.14.1
A postfix expression followed by a ++ operator is a postfix increment expression. The result of the postfix expression must be a variable of a numeric type, or a compile-time error occurs. The type of the postfix increment expression is the type of the variable. The result of the postfix increment expression is not a variable, but a value.

The key difference between the two sentences in red is that the first refers to a posfix expression, while the second refers to a postfix increment expression. Look again at the very first sentence of the quote - those are two different things. In the case of "x++", "x" by itself is a postfix expression, and "x++" is a postfix increment expression. So "x" must be (and is) a variable of numeric type, and "x++" is not a variable, but a value. Clear?

[This message has been edited by Jim Yingst (edited November 10, 2000).]
 
Subha Guhan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim
I removing my rattling post in the light of what you have said.
Subha
 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well first of all let me thank you for clearing my doubt. I had posted the same question on certification forum but nobody noticed it.
I must admit that I was not very careful while reading that section. But my longstanding doubt has been cleared, so I must thank Jim again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic