POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Teach yourself C++ in 21 strange malfunctions Server Time
29 Jul 2024 16:32:24 EDT (-0400)
  Re: Teach yourself C++ in 21 strange malfunctions  
From: Invisible
Date: 18 Apr 2012 04:04:14
Message: <4f8e757e@news.povray.org>
On 17/04/2012 08:51 PM, Warp wrote:
> Invisible<voi### [at] devnull>  wrote:
>> I'm still a bit baffled that this is a valid thing to do, however...
>
>    There's some baggage from C that would have better been dropped, but
> as you may know, backwards compatibility can be a real b***h sometimes...

Don't we all know it. ;-)

(Haskell isn't as ancient as C, so fortunately it has much less of this. 
It /does/ have it, however...)

>    It can be argued using the same logic as with uninitialized variables,
> though: There are situations where execution never reaches the end of the
> function, and hence having a 'return' statement there would be useless.

Sure. But like I said, the Java compiler seems to detect this. If 
doesn't just look at a function and say "does it contain a return 
statement somewhere?" It actually statically analyses every possible 
flow of control, and checks that every individual one ends with a return 
(or throws an exception, which is also a valid way to terminate a function).

Of course, it's not perfect. Plausibly you could have if branches such 
that a particular sequence of branches is impossible due to the 
conditions in those branches, but the compiler wouldn't "see" that and 
would still insist that you have a branch that doesn't terminate 
properly. But I haven't seen that happen yet.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.