POV-Ray : Newsgroups : povray.off-topic : Computer language quirks : Re: Computer language quirks Server Time
30 Jul 2024 04:18:18 EDT (-0400)
  Re: Computer language quirks  
From: Patrick Elliott
Date: 13 May 2011 04:25:08
Message: <4dcceae4$1@news.povray.org>
On 5/13/2011 12:44 AM, Zeger Knaepen wrote:
> On 12/05/2011 1:19, Darren New wrote:
>> On 5/11/2011 13:27, Warp wrote:
>>> C# isn't C++...
>>
>> I know that. I'm just saying that I was surprised it worked in C++
>> because everything I've ever read except the standard implies it
>> shouldn't. Every tutorial etc etc etc says "You can't put a value after
>> a return in a void function, and you have to put a value after a return
>> in a non-void function." So it surprised me this was actually not true
>> for C++. So I figured I'd try specifically for C#, because maybe all the
>> tutorials for *that* were wrong. :-)
>
> except that your "value" is actually a non-value by itself:
>
> the function "bar" doesn't return anything, so if "foo" returns the
> return-value of "bar", it also doesn't return anything.
>
> I suppose it wouldn't work if "bar" really had a return-value.
>
> cu!
Hmm. Interesting point. Its possible that over the long time C++ 
compilers have been around a test was added to it, which simply tossed 
the return functions, in cases where the result would never produce 
output. Mind, a warning would have made more sense on those, at least.

Possible you might have an overloaded function, possibly, that would be 
void in some cases, or return a value in others, thus it would be 
perfectly reasonable to both get nothing from such a function, as well 
as return something, in the case of bar(). Bar itself doesn't attempt to 
return a value. The other one should, I would think, at least throw a 
warning that you are trying to return a result in a function that 
doesn't support it. Whether it should be an error, instead of a warning 
though...

But, very odd.


Post a reply to this message

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