C
cimple
I've always made sure never to have multiple return paths in a function
because i thought it produced bigger code (and for readability). I
remember Lippman from Inside the Object Model saying something about
this. For every return point in a function, destructor calls for every
object created on the stack needs to be called. But when i tested this,
i saw no increase in executable size in release builds. Is my compiler
(VS7.0, Win2k) just optimizing or was my original assumption incorrect?
For example:
void Foo()
{
Object x;
Object y;
Object z;
if (x == y)
return;
if (x == z)
return;
if (y == z)
return;
}
Doesn't the above Foo bloat into this:
void Foo()
{
Object x;
Object y;
Object z;
if (x == y)
{
x.~x();
y.~y();
z.~z();
return;
}
if (x == z)
{
x.~x();
y.~y();
z.~z();
return;
}
if (y == z)
{
x.~x();
y.~y();
z.~z();
return;
}
x.~x();
y.~y();
z.~z();
return;
}
Hence, never produce functions with multiple return paths?
Thank you in advance.
because i thought it produced bigger code (and for readability). I
remember Lippman from Inside the Object Model saying something about
this. For every return point in a function, destructor calls for every
object created on the stack needs to be called. But when i tested this,
i saw no increase in executable size in release builds. Is my compiler
(VS7.0, Win2k) just optimizing or was my original assumption incorrect?
For example:
void Foo()
{
Object x;
Object y;
Object z;
if (x == y)
return;
if (x == z)
return;
if (y == z)
return;
}
Doesn't the above Foo bloat into this:
void Foo()
{
Object x;
Object y;
Object z;
if (x == y)
{
x.~x();
y.~y();
z.~z();
return;
}
if (x == z)
{
x.~x();
y.~y();
z.~z();
return;
}
if (y == z)
{
x.~x();
y.~y();
z.~z();
return;
}
x.~x();
y.~y();
z.~z();
return;
}
Hence, never produce functions with multiple return paths?
Thank you in advance.