• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Unreachable Vs Dead Code

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Why I am getting compile warning as given in the comments.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raja Narasimha wrote:Hi, Why I am getting compile warning as given in the comments.



Because of these two lines..
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the difference between Dead code and Unreachable code.
 
Raja Narasimha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, What I am trying to ask is, Line# 5 is guaranteed to execute. As soon as the control finishes executing Line 5, Control should come out of the method. My question is why it should not be "Unreachable code" instead of "Dead Code" ? Hi Abimaran, one of your links says "Unreachable code is sometimes also called dead code" which is confusing me more.

Abimaran Kugathasan wrote:Check the difference between Dead code and Unreachable code.

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both are different, Unreachable code : the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program, and Dead code : the source code of a program which is executed but whose result is never used in any other computation. So, for an example, the below code is an unreachable code,


You can see a unreachable statement in the above code.
 
Raja Narasimha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. In your program is guanteed to execute, so you will get the error if you write any statement after that.

In my code, Lines 1-4 is guaranteed to execute and we are returning out of the method at Line 3. How can we return again at Line 5. It should not make any sense whether it is executed or not. Please let me know I am assuming that the above 5 lines of code can be written as given below but this gives error
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raja Narasimha wrote:Yes. In your program is guanteed to execute, so you will get the error if you write any statement after that.

In my code, Lines 1-4 is guaranteed to execute and we are returning out of the method at Line 3. How can we return again at Line 5. It should not make any sense whether it is executed or not. Please let me know I am assuming that the above 5 lines of code can be written as given below but this gives error



What you have forgot is, the compiler don't know the logics, it knows only the syntax!
 
I once met a man from Nantucket. He had a tiny ad
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic