Why return do not terminate function in MS C2008 ++ ?

Posted on 2011-10-08
Last Modified: 2012-05-12
 Hi experts!

I'm new to MS C++ 2008 and need little help. I read in manual that return should break current execituon of the function, but after I finish my project by accident I find that look that is not true. Look my code:

long CCPlayCtrl::SetToZeroRemainTimeCurrFile(long lCard)
//  ... code

   if (!bFind)
          return -98; //Here should exit from function?!? Why do not exit and contunie with next code???

// next code write a message to the text file. I was shocked to find that bFind=false, return -98 is executed and function execution  just contunie with next row of code. WHY ???
         if (mbWriteAllCmd[lCard])
             sLog.Format( _T( "CCPlayCtrl::SetToZeroRemainTimeCurrFile-->bFind=false !!!\n" ));

            lStradisDecoderSettingsFrame[iIndex]=0; lStradisDecoderSettingshWng[iIndex]=0;
            return 0;


Do i need to change all situations like this in my code, or this is some specific case? In any case I should know what is going on. To be more clear, this is ActiveX project (OCX) and this is one of his public functions.
Question by:dvplayltd
    LVL 86

    Accepted Solution

    Well, apparently 'bFind' does not seem to be 'false' - can you double check that? I know it's kinda stupid, but otherwise, the whoe thing should work.
    LVL 53

    Assisted Solution

    >> I was shocked to find that bFind=false

    I just see a string literal stating that bFind is false.
    I don't see an actual check for that.

    >>    if (!bFind)
    >>           return -98; //Here should exit from function?!? Why do not exit and contunie with next code???

    If the function didn't return there, it means that bFind was true at that point ... Try following what happens with bFind to get a better idea of what's going on.

    Author Closing Comment

    10x. In final case you are right, bFind is not false, sorry for stuped question.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now