9

I have a local variable that is completely unused, can be of any name or type as long as it's assigned.

Yet, if I delete it the program no longer works.

Huh?

Comments
  • 1
    What does it contain and if yes, when does it's content change?
  • 1
    Are you using JS?
  • 2
    @CWins can be of any type so long as it's assigned, no optimisations enabled.

    It's never referenced, used or changed anywhere.
  • 1
  • 1
    @Jamoyjamie didn't see the tag before 😅
  • 1
    Had nearly the same Problem, if I delete one line where just the Parameter of one object is read and nothing is done with the value except printing it, it crashes. Kinda weird
  • 1
    @Jamoyjamie
    I didn't ask if it is used by anything explicitly in your code, i asked if it changes ;-)

    If that piece of reserved memory is important, what needs it to work?
    C++ allows you to put your pointers and indices in positions that are not intended.

    And what do you mean by assigned, did you try to fill true in every bit or does it only work with numbers like 0 and slightly above?
  • 2
    @CWins Sorry!
    The line is literally a local variable declaration at the top of a function:
    float cf = 1.0f;
    Didn't try a whole host of possible values but tried a few different floats and tried changing to a char and other types to see if data size mattered and it didn't.

    The variable isn't ever explicitly referenced anywhere so I do expect it's a pointer that's started misbehaving.

    I need to get a debugger on it tomorrow, not a big C++ person so still finding my way round tools etc.

    I don't expect you to be able to help with such little information don't worry! 🙂
Add Comment