trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: January 2012

Re: [trinity-devel] C++ Question

From: Patrick Serru <patrick@...>
Date: Mon, 16 Jan 2012 13:24:25 -0500
Le lundi 16 janvier 2012, Darrell Anderson a écrit :
> When a C++ (boolean) function contains multiple if-else tests, and each of
> those tests contains a return statement (return=false; or return=true;),
> does the function exit when encountering the first return?
> 
> Or does the function continue executing the remaining code within that
> function?
> 
> In other words, when encountering that first return, does the function
> exit much like a break command?
> 
> Darrell
> 
---------------------------------------------------------------------
      Hi everybody,

      If it returns on this instruction "return=false;", does this writing
supose that the "=" operator had been overloaded? Can someone tel me the 
interest of overloading the "=" operator for a return instruction? It just 
looks to me like adding ambigiusity, even if the reader knows that "return" 
is a reserved word and not an variable identifier. The old 
K&R "return(expression);" looks definitively clearer to me.

      I personely would write something like
if (IsRouge()) return(Red());
if (IsJaune()) return(Yellow());
      ... rather than
if (IsRouge) return(Red());
else if (IsJaune return(Yellow());
      Is'nt that "else" keyword adding ambigiusity, reason why this thread 
exists? Furthermore: depending of the compiler and optimisation, I suppose 
that code could be added because the "else" keyword existance.

      Thank you,
Patrick