cancel
Showing results for 
Search instead for 
Did you mean: 

Function return issue

Workalot
Associate III
Posted on April 06, 2010 at 00:21

Function return issue

3 REPLIES 3
luca239955_stm1_st
Senior II
Posted on May 17, 2011 at 15:07

Hi,

you are putting the result of your function into a local variable that is never used -> it is probably optimized out.

Try to use a global variable, it should work.

Regards,

Luca (Cosmic)

Workalot
Associate III
Posted on May 17, 2011 at 15:07

Ok - by having...

int main( void )

{

  unsigned short usResult;

  usResult = Func();

  if ( 0 == usResult )

  {

      usResult = 1;

   }

  while( 1 );

  return0;

}

... does get a returned value in usResult since it is referenced after the call to func(). So, compilers are getting that clever - even on a debug build with no optimization. 

Always a new lesson to learn in this business - thank you for your response.

luca239955_stm1_st
Senior II
Posted on May 17, 2011 at 15:07

>> So, compilers are getting that clever - even on a debug build with no optimization

Actually optimizations are done in different compiler passes: the parser, the code generator and the optimizer itself: when you ''turn off the optimizations'' you justr disable the last component.