Skip to main content
Visitor II
April 5, 2010
Question

Function return issue

  • April 5, 2010
  • 3 replies
  • 641 views
Posted on April 06, 2010 at 00:21

Function return issue

    This topic has been closed for replies.

    3 replies

    Visitor II
    May 17, 2011
    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)

    WorkalotAuthor
    Visitor II
    May 17, 2011
    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.

    Visitor II
    May 17, 2011
    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.