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?

  • 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 '19 at 23:53
  • Have you looked on stackoverflow ? Many solved questions there are about similar symptoms – Christophe Sep 20 '19 at 15:20
  • Accessing a variable before it is initialized is undefined-behaviour as per the spec. stackoverflow.com/questions/367633/… – Sisir Sep 25 '19 at 11:36
  • On a related context check this as well stackoverflow.com/questions/367633/… – Sisir Sep 25 '19 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 :-)

| improve this answer | |

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