"The variable has been removed during optimization and is not available".
Sometimes I really hate Visual Studio...

  • 12
    Don't hate the tool just because you can't be bothered to turn off optimisation in debug
  • 3
    In C you can add volatile to variables, maybe it works in C++ too, optimizers won't optimize volatile variables
  • 5
    lol why does the compiler remove variables it needs? wtf is going on

    that doesnt really count as "optimisation", but rather as "breaking"
  • 5
    @simulate if it runs optimized it isn't breaking.
  • 3
    @simulate the errors are in the watch. People need to learn more about the platform and compiler they're working on.
  • 0
    @IllSlapU normally you attach it in front of the variable like „volatile double variableName“
    In my C class we had a similar problem like OP in our C Code. the teacher told us to use volatile so the optimizer would ignore this specific variable.
  • 10
    volatile means the value can change without a explicit write from the program. Therefore a volatile variable is always read from its memory location and not assumed to be unchanged between two read operations. Generally this keyword is only needed in low-level applications (peripheral access, dealing with interrupts).
  • 1
  • 1
    @D--M we turned of optimization and the program ran through. This is not about being to lazy to turn of optimization but the fact that the it randomly removed values.
  • 3
    @IRonnyc You are running optimised so instead of copying the value to p it will just look into the array. It is not removing any values just avoiding unnecessary allocations
  • 0
    @fuckwit sounds right.
    I shared the picture mostly because the debugger said it had been removed by optimization.

    @irene I think the values were actual NaN values because when we fixed the calculation for the values it suddenly worked.
    (in a vector magnitude calculation somebody wrote something like sqrt(x^2 * y^2 + z^2))
  • 0
    @demortes @AndSoWeCode @irene
    ah, I get it. yeah ok you cant expect full watch support for an optimised application. I thought those were compiler errors.
  • 0

    My point still stands, you ran the program with optimization and you clearly don't know what that means.
  • 0
    @irene that makes sense.
    Still the watches should have shown the value of p (at least it does in other languages and other IDEs).

    @D--M you're at least partially right. I'm no expert in assembly, I'm no expert when it comes to what the compiler optimizes and I'm no expert in C/C++ using visual studio. I don't think I ever said I were an expert.
    Currently I'm mostly programming using C# and Java.
    I know basic stuff about optimization; the compiler will optimize the code to improve performance.
    Higher optimization often means more in lining, unwrapping of loops etc. while sometimes even removing unnecessary stuff, making it harder and harder to debug your code. That's why one should use /Od for debugging....
    If you're really going for performance you can use memory alignment to reduce the size of classes in memory making the whole thing more cache friendly.
    (Yes I did look up the flag, I don't have a problem admitting that.)
    No matter how high the optimization is, it shouldn't change the output of what you receive...
    I'm not quite sure if the optimization did change to output that was written to the file. We found what you can see in the image while trying to find the source of some NaN values that were written to that file, making it unusable... (three.js json file if you care)
Add Comment