Question:

Is there a C/C++ static analysis tool that will check for one function to follow another?

by  |  earlier

0 LIKES UnLike

I have a series of functions that set a return code (rc), and I need to make sure that every time rc is set, it is checked for an error.

 Tags:

   Report

2 ANSWERS


  1. If the return code is an object, then it can check itself on assignment and throw an exception.

    A primitive integer cannot of course do this.

    Another hack would be to use a macro or method to control access to the return code. The macro would check for error.

    Update:

    A macro is a preprocessor construct. The macro is ultimately replaced by whatever code the macro represents before compilation. The best way to guarantee your return code is always evaluated is to define a new ReturnCode class that validates input on construction or assignment.

    E.g.

    class ReturnCode

    {

    public:

    ReturnCode( int returnValue )

    {

    // check return value here

    }

    ReturnCode& operator=( int returnValue )

    {

    // check return value here

    returrn *this;

    }

    };

    // Example usage...

    ReturnCode rc = SomeFunctionCall( );


  2. Yes you can check the static analysis tool C++test from parasoft.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.