This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange thing about char.

 
Yuan Ye
Ranch Hand
Posts: 172
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supposing we have following defination:
char c = 10;
int i = 20;
I understand why c=c+i can't be compiled. But why c+=i can be compiled? Please help.
Thanks
 
Fahad Fahad
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually this is casting.
complier does explicit casting when using
c+=i;
this is equal to
c= char(c + i);
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Similar vquestion has been posted before. Here's the url
 
Yi Meng
Ranch Hand
Posts: 270
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

c= char(c + i);

should be c=(char)(c+i);
For expressions like opt1+=opt2; they can always interpreted as:
opt1=(T)(opt1+opt2);
where T is the type of opt1. This also applies to operators such as : -+, *=, /=, etc
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic