This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Static Variables

Hi everyone,

I would like to know if something similar happen to you. Well the issue is that when I declare a variable as a global one in the header file of a module with extern sometimes it loses its value. And if I declare it as static I can not access to it from other module. As far As I understand, a static variable is the same during the all of the execution of the program and it has a space of memory reserved to it. Can anyone please clarify this?

Thanks in advance.

Parents
  • Hello!

    I experienced the same behavior, but debugging the code I could see it's not that the global variable had lost its content ... (that was my first thought)

    It seems like loses its scope. It is strange in a global variable right?
    At the beginning of the function I can manage it properly, but later in the same function can not even compare it to a value or assign its value to another variable. Strangely, if I halt there the debug and pass the mouse over the global variable, popup values are correct. But makin the next step in debug takes no effect.

    I know that the variable retains its value because if I create a dummy function call it from where it fails and doing the assignment or comparison there, works fine...

    In dissasembly I can see that one of the register involved has not the correct offset, so I'm focusing in optimization levels to see if i can find out where is the problem.

    Please, if anyone can help...

    Thank you very much in advance.

Reply
  • Hello!

    I experienced the same behavior, but debugging the code I could see it's not that the global variable had lost its content ... (that was my first thought)

    It seems like loses its scope. It is strange in a global variable right?
    At the beginning of the function I can manage it properly, but later in the same function can not even compare it to a value or assign its value to another variable. Strangely, if I halt there the debug and pass the mouse over the global variable, popup values are correct. But makin the next step in debug takes no effect.

    I know that the variable retains its value because if I create a dummy function call it from where it fails and doing the assignment or comparison there, works fine...

    In dissasembly I can see that one of the register involved has not the correct offset, so I'm focusing in optimization levels to see if i can find out where is the problem.

    Please, if anyone can help...

    Thank you very much in advance.

Children