• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this an implicit cast?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do Try This ,it will help,we know final variable act as constant.
 
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic