1

I'm running a program in C++ on a Chromebook Penguin terminal. The program runs perfectly the first time, but on consecutive runs it acquires different results. I suspect that this is because the terminal remembers the variables from before. Is there any way to resolve this issue in my code?

closed as off-topic by gnat, BobDalgleish, 17 of 26, Christophe, Bart van Ingen Schenau Sep 23 at 14:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking for assistance in explaining, writing or debugging code, or using coding tools, are off-topic here. These can be asked on Stack Overflow if they include the desired behavior, a specific problem or error, and a Minimal, Reproducible Example of the problem." – gnat, BobDalgleish, 17 of 26, Christophe, Bart van Ingen Schenau
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    A C++ program specifies well-defined initial state of its global (and static) variables. However, C++ programs are not immune to uninitialized local & heap variables (a programmer error), and that could be an issue. Can you identify what causes it to resume running perfectly (like rebooting)? – Erik Eidt Sep 19 at 23:53
  • Have you looked on stackoverflow ? Many solved questions there are about similar symptoms – Christophe Sep 20 at 15:20
  • Accessing a variable before it is initialized is undefined-behaviour as per the spec. stackoverflow.com/questions/367633/… – Sisir Sep 25 at 11:36
  • On a related context check this as well stackoverflow.com/questions/367633/… – Sisir Sep 25 at 11:37
2

This is most likely a problem with your code (such as relying on uninitialized variables, or more likely working with external files or other state that are not cleared before each run).

So, the answer is "yes", you can fix it in your code by identifying and fixing the bugs.

Have you tried running the program in a different environment such as a vanilla linux system? If not, it's probably a bit premature to put the blame on Chromebook penguin :-)

Not the answer you're looking for? Browse other questions tagged or ask your own question.