|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> 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...
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.
In most situations putting such a useless 'return' there is only a minor
inconvenience, but in theory it could be more complicated. Also, it makes
the function larger, so the 80's C hackers didn't like that (in the same
way as they didn't like the idea of spending a clock cycle to initialize
a variable with a value that would immediately be overwritten anyways).
This would be an example of such a function:
std::string foo(int parameter)
{
assert(parameter >= 0 && parameter < 4);
switch(parameter)
{
case 0: return "Hello";
case 1: return "there";
case 2: return "world";
case 3: return "!";
}
// Execution will *never* reach here
// It's valid to omit a 'return'
}
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |