PreviousNext
Optimized return TRUE/FALSE
Help > Appendix > Code Optimization > Optimized return TRUE/FALSE

FLASH-                        RAM                Speed-

 

Each return TRUE or return FALSE actually requires two instructions. If there are more such statements it is more efficient to implemented function to just return TRUE or FALSE and to return their value. This leads just to one goto instruction.

 

bit MyFunction()

{

  // Do something

  if ( condition )

       return FALSE;

  // Do something

  return TRUE;

}

 

bit returnTRUE()

{

  return TRUE;

}

 

bit returnFALSE()

{

  return FALSE;

}

 

bit MyFunction()

{

  // Do something

  if ( condition )

    return returnFALSE();

  // Do something

  return returnTRUE();

}