• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this an implicit cast?

 
Adrian Stent
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why doesnt 'g' require a cast back down to byte after arithmetic is performed? The variable 'h' requires an explicit cast as the variables are promoted to int for the arithmetic.


Hope someone can explain this to me..
 
Roopesh Gulecha
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian,
In the example g doesn't require a cast because what is assigned to it is
1. compile time constant integer (value 13)..(no variables involved), and
2. the constant fits in the type byte.
So the compiler is happy...

whereas variable h is assigned values of another variable(s), which is not considered compile time constant (unless the variable is a final constant)..to the compiler it means that the value of the variable may change while the program is running, so it flags an error.

Hope this helps.

Roopesh.
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do Try This ,it will help,we know final variable act as constant.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank U Mr. roopesh
The Information given by U was Basi information. But Worth forgetting


######33
Agrah upadhyay
3rd Year
Bioinformatics
 
Adrian Stent
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, that makes sense it being a compile time constant within the range of the variable. The code proves it as well.

Cheers.
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Dont Think We Should Comment on any post,what i know that mr Roopesh provided us with a very simple and good and informative logic,and for every posting one should be appreciated,so Thanks mr Roopesh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic