Getting "an unspecified error has occurred" or "identifier 'result' is undefined" in Visual studio

Noa Halali 15 Reputation points
2023-04-16T17:27:01.9333333+00:00

Hello, my project is working and do everything I need, but when i'm debugging it, in one of the locals I can't see the value but those messeges and a rex X from the left, I can see that the valuses in the "result" changed after the function but while the function is running it's like the watch/autos aren't recognize"result". i'd like for some help to understand what's wrong User's image

User's image

Developer technologies | Visual Studio | Debugging
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
{count} votes

3 answers

Sort by: Most helpful
  1. Anna Xiu-MSFT 31,151 Reputation points Microsoft External Staff
    2023-04-18T08:46:38.19+00:00

    Hi @Noa Halali

    Welcome to Microsoft Q&A! 

    Please try to disable Optimization: right-click on Project > Properties > Configuration Properties > C/C++ > Optimization > Optimization: Disabled (/Od). 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Kevin Mayrhofer 0 Reputation points
    2023-07-21T15:55:53.0133333+00:00

    I have the same problem. For whatever reason it only happens with structs.
    And even weirder: Only with the struct I return.

    So in OPs example if in the function I do something like this:

    Student unScramble(List lst){
        Student result;
        Student working;
    
        ...
    
        return result;
    }
    

    If I return result I can't debug result. But I can debug working.

    If I return working it's vice versa.

    I'm running in Debug mode.

    Sincerly,

    Kevin

    0 comments No comments

  3. Felipe Guedes da Silveira 0 Reputation points
    2023-12-01T16:43:51.59+00:00

    The exact behavior described by @Kevin Mayrhofer still happens as of VS2022 17.7.5.

    It's not possible to introspect on the values of returned struct objects using the debugger.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.