locked
Array with input/output

    질문

  • 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


    • 편집됨 Bengt G 2012년 4월 27일 금요일 오전 6:56
    2012년 4월 26일 목요일 오후 1:17

답변

모든 응답

  • 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

    2012년 4월 30일 월요일 오전 2:58
    중재자
  • 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

    2012년 4월 30일 월요일 오전 9:02
  • 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

    2012년 5월 1일 화요일 오전 5:33
    중재자