locked
Array with input/output

    Question

  • Hi!

    I have code that passes information in arrays of integers. For example: The first word is return code, the following two are input, such as:

    int sv[3];
    sv[1] = x;
    sv[2] = y;
    myroutine(sv);
    if (sv[0] == 0) {  /* Success */
    ...

    I currently declare the parameter to myroutine as __inout_ecount(3). However, I would like to tell the code analyzer what is input and what is output. In particular I want to find if there are code sequences where myroutine does not set the return code. With the current declaration that (obviously) does not happen.

    Sometimes sv[0] is also input. In this case I still require my routine to set the first word. I.e. I never want the function code left as return code. Can this be done?

    Thanks


    Bengt


    • Edited by Bengt G Friday, April 27, 2012 6:56 AM
    Thursday, April 26, 2012 1:17 PM

Answers

All replies

  • Hi Bengt,

    Thank you for visiting the MSDN forum.

    I would like to tell the code analyzer what is input and what is output. In particular I want to find if there are code sequences where myroutine does not set the return code. With the current declaration that (obviously) does not happen.

    Would you mind providing detailed information? Do you mean that you want to use the Visual Studio Code Analysis and Code Metrics tool to get what is input and what is output in your code?

    It seems that it is the C++ project, if so, did you try to use this tool to analyze this C++ project? What results did you get?

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 30, 2012 2:58 AM
  • Hi Jack,

    I am using Visual Studio 11 Beta from C++. I run Code Analysis From Solution from the Build menu. Consider the following two (meaningless) routines:

    void myroutine(__inout_ecount(3) int sv[3])
    {
        if (sv[1] > 10) {
            sv[2] = sv[2] + sv[1];
            /* Forgot to set return code in sv[0] here */
        } else {
            sv[2] = sv[1];
            sv[0] = 0;     /* Set return code to ok */
        }
    }
    
    void myroutine2(__out int *rc, __inout_ecount(3) int sv[3])
    {
        if (sv[1] > 10) {
            sv[2] = sv[2] + sv[1];
            /* Forgot to set return code here */
        } else {
            sv[2] = sv[1];
            *rc = 0;
        }
    }

    In myroutine2 I declare *rc as __out. When I run the code analyser it will give me error code C6101: returning uninitialized memory. I want to do the same thing for myroutine. How can I tell the code analyser what elements in my array are input and which ones are output? I would like to say that element [0] is output and element [1] is input/output and [2] is input.


    Bengt

    Monday, April 30, 2012 9:02 AM
  • Hi Bengt,

    As far as I know, there is no such mode in Visual Studio when we run Code Analysis on C++ project. I did some research about this issue, but I didn’t get any useful information. But The Visual Studio product team is listening to user voice at http://visualstudio.uservoice.com/forums/121579-visual-studio .You can send your suggestions and ideas there and people can vote. Thanks for your understanding.

    Have a nice day,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 01, 2012 5:33 AM